diff --git a/app/api/controller/Wxserver.php b/app/api/controller/Wxserver.php index 7f54ed2d..f73968c7 100644 --- a/app/api/controller/Wxserver.php +++ b/app/api/controller/Wxserver.php @@ -7,6 +7,13 @@ use cores\BaseController; class Wxserver extends BaseController { + public function index() + { + $obj = new \app\common\library\wxserver\Server(); + $data = $obj->getQrcode('wxe3ed157849bd07b5'); + return $this->renderSuccess($data); + } + public function verifyTicket() { $xmlData = file_get_contents("php://input"); diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index 1cbffd25..056d8c18 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -126,7 +126,38 @@ class Server } /** - * @notes:发布版本 + * @notes:获取体验码 + * @param $appid + * @return array|mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function getQrcode($appid) + { + $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) { + $url = 'https://api.weixin.qq.com/wxa/get_qrcode?access_token=' . $access_token; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 如果你的环境没有安装证书,可以设置为 false,但生产环境不建议这样做 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 同上 + $qrcode_response = curl_exec($ch); + curl_close($ch); + return json_decode($qrcode_response, true); + } + } + return []; + } + + /** + * @notes:发布体验版 * @param $appid * @param $template_id * @return bool