|
@@ -13,7 +13,6 @@ use think\Validate;
|
|
|
|
|
|
use think\Db;
|
|
|
use miniprogram\wxBizDataCrypt;
|
|
|
-use GuzzleHttp\Client;
|
|
|
|
|
|
/**
|
|
|
* 会员接口
|
|
@@ -663,53 +662,4 @@ class User extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 小程序码
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function getMiniCode()
|
|
|
- {
|
|
|
- try {
|
|
|
- $companyId = $this->request->param('company_id',0);
|
|
|
- if (empty($companyId)) {
|
|
|
- throw new Exception('参数错误');
|
|
|
- }
|
|
|
- $companyWhere['id'] = $companyId;
|
|
|
- $companyWhere['status'] = 1;
|
|
|
- $company = Db::name('company')->where($companyWhere)->find();
|
|
|
- if (empty($company)) {
|
|
|
- throw new Exception('未找到门店信息');
|
|
|
- }
|
|
|
- $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
|
|
|
- if (empty($company['mini_code'])) {
|
|
|
- $client = new Client();
|
|
|
- $tk = getAccessToken();
|
|
|
- $res2 = $client->request('POST', 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk, [
|
|
|
- 'json' => [
|
|
|
- //'page' => 'pages/home/index',
|
|
|
- 'env_version'=>'trial',
|
|
|
- 'scene' => 'shopId='.$companyId,
|
|
|
- ]
|
|
|
- ]);
|
|
|
- $fileName = md5($companyId);
|
|
|
- $fileUrl = '/uploads/company/'.$fileName.'.png';
|
|
|
- $code = $res2->getBody()->getContents();
|
|
|
- file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code);
|
|
|
- $companyData['mini_code'] = $fileUrl;
|
|
|
- $companyRes = Db::name('company')->where($companyWhere)->update($companyData);
|
|
|
- if (!$companyRes) {
|
|
|
- throw new Exception('更新门店信息失败');
|
|
|
- }
|
|
|
- $miniCode = $httpStr.$fileUrl;
|
|
|
- } else {
|
|
|
- $miniCode = $httpStr.$company['mini_code'];
|
|
|
- }
|
|
|
- $result = [
|
|
|
- 'mini_code' => $miniCode,
|
|
|
- ];
|
|
|
- $this->success('获取成功',$result);
|
|
|
- } catch (Exception $e) {
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
}
|