小程序太阳码 ,不发布也可以测试
作者:互联网
/**
* 获取小程序太阳码
*/
public function getXcxCodeUrl($access_token,$scene,$page,$check_path = true,$env_version = 'release') {
$request_data = [
'page' => $page, // 如: pages/index/index 。 这里pages前面没有斜杠'/' 。
'scene' => $scene,
'check_path' => $check_path,
'env_version' => $env_version, // 必须结合check_path使用,要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
'width' => 690
];
$request_url='https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$access_token;
$result = Http::doPostJson($request_url,$request_data);
// dump($result);exit;
// ob_clean();
// header('Content-Type: image/png; charset=UTF-8');
// echo $result;exit;
$uploadService = new UploadService();
// 存入cdn
$cdn_result = $uploadService->upload_cdn($result,'suncode');
if ($cdn_result['errno'] == 0) {
return $cdn_result['save_name'];
} else {
return false;
}
}
小程序端解析
if (options.scene != undefined) { //微信直接扫码
var scan_url = decodeURIComponent(options.scene);
console.log(scan_url);
this.setData({
id: this.getQueryString(scan_url, 'id')
})
} else { //内部扫一扫
this.setData({
id: options.id
})
}
//解析链接
getQueryString: function (url, name) {
// console.log("url = " + url);
// console.log("name = " + name);
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i');
var r = url.substr(1).match(reg);
if (r != null) {
// console.log("r = " + r)
// console.log("r[2] = " + r[2])
return r[2];
}
return null;
},
使用
/**
* 生成小程序太阳码
*/
public function generateQrcode() {
$wxService = new WxService();
$accessToken = $this->getToken();
$xcxcode = $wxService->getXcxCodeUrl($accessToken,'?id=15','pages/riskPoint/index');
$this->json->ok($xcxcode);
}
标签:console,name,url,cdn,程序,scene,太阳,result,测试 来源: https://www.cnblogs.com/jiqing9006/p/15705593.html