<?php
namespace addons\gaga\library\cqrs\libs;
use think\exception\ValidateException;
class Wxaqrcode
{
protected $wxapp_settings;
protected $default_wxapp_settings;
private $appId;
private $appSecret;
private $access_token;
private $error = '';
public function __construct($app_id,$app_secret)
{
if (empty($app_id) || empty($app_secret)) throw new \think\Exception('小程序参数错误');
$this->appId = $app_id;
$this->appSecret = $app_secret;
$access_token = \think\Cache::get('wxa:access_token:' . $this->appId);
if (!$access_token) {
$target_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appId . "&secret=" . $this->appSecret;
$res = $this->http_get($target_url);
$res = json_decode($res, true);
if (isset($res['errcode']) && $res['errcode'] != 0) {
$content = '';
switch (!$res || $res['errcode']) {
case 40001:
$content = "AppSecret错误或者AppSecret不属于这个小程序,请开发者确认AppSecret的正确性";
break;
case 40164:
$content = "调用接口的IP地址不在白名单中,请在接口IP白名单中进行设置";
break;
}
throw new ValidateException($content);
}
$access_token = $res['access_token'];
$expire = $res['expires_in'] ? intval($res['expires_in']) : 7200;
\think\Cache::set('wxa:access_token:' . $this->appId, $res['access_token'], $expire);
}
$this->access_token = $access_token;
}
public function getWxQrcode($page = 'pages/index/index', $scene = '', $width = 430, $filepath = null, $qrtype