wang hou sheng 8 months ago
parent 64f475a39f
commit 140ded75b6
  1. 16
      app/common/library/wxserver/Server.php

@ -5,6 +5,7 @@ namespace app\common\library\wxserver;
use app\common\model\WxserverAccount;
use cores\exception\BaseException;
use Qiniu\Http\Client;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -136,24 +137,27 @@ class Server
*/
public function getQrcode($appid)
{
$savePath = root_path() . "public/wxserve/experience";
!is_dir($savePath) && mkdir($savePath, 0755, true);
$savePath .= '/' . $appid . '.jpg';
if (file_exists($savePath)) {
return '/wxserve/experience/' . $appid . '.jpg?time=' . time();
}
$model = new WxserverAccount();
$info = $model->where(['appid' => $appid])->find();
if (!empty($info)) {
$info = $info->toArray();
$access_token = $this->authorizerAccessToken($appid, $info['refresh_token']);
if ($access_token) {
$savePath = root_path() . "public/wxserve/experience";
!is_dir($savePath) && mkdir($savePath, 0755, true);
$savePath .= '/' . $appid . '.jpg'; //Client
$url = 'https://api.weixin.qq.com/wxa/get_qrcode?access_token=' . $access_token;
$client = new \Qiniu\Http\Client();
$client = new Client();
$response = $client->get($url);
$res = $response->body();
if ($res) {
$newFile = fopen($savePath, "a");
fwrite($newFile, $res);
fclose($newFile);
return '/wxserve/experience/' . $appid . '.jpg';
return '/wxserve/experience/' . $appid . '.jpg?time=' . time();
}
}
}
@ -195,7 +199,7 @@ class Server
}
$data['template_id'] = $template_id;
$data['user_version'] = $version;
$data['user_desc'] = $desc;
$data['user_desc'] = urlencode($desc);
$ext_json['extAppid'] = $appid;
$ext_json['ext']['store_id'] = $info['store_id'];
$ext_json['window'] = [];

Loading…
Cancel
Save