1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 微信公众号生成带参数二维码

微信公众号生成带参数二维码

时间:2019-06-11 05:02:21

相关推荐

微信公众号生成带参数二维码

/*** 生成推广二维码*/public function create_qrcode() {$res = Db::name("user")->field("reffer_code,openid")->where("id", $this->auth->id)->find();// QR_SCENE QR_STR_SCENE 临时二维码 QR_LIMIT_SCENE QR_LIMIT_STR_SCENE 永久二维码$arr = ['action_name' => 'QR_STR_SCENE','action_info' => ['scene' => ['scene_str' => $res['reffer_code']]]];$data = json_encode($arr);$url = 'https://api./cgi-bin/qrcode/create?access_token=' . $this->getAccessToken();$result = $this->CURLSend($url, 'post', $data);$results = json_decode($result, true);// echo "<pre>";var_dump( $url , $results );die;$qecodeUrl = 'https://mp./cgi-bin/showqrcode?ticket=' . UrlEncode($results['ticket']);$this->success('ok', ['reffer_code' => $res['reffer_code'],'qrcode_src' => $qecodeUrl,]);}//获取access_token,微信调用接口凭据(使用接口需要用到)public function getAccessToken() {$config = Db::name('app_public')->where('id', 1)->find();if( $config['wx_expires_in']< time() ){$appid = $this->appid;$appsecret = $this->appsecret;$url = "https://api./cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret;$tmp = $this->CURLSend($url, 'get');$obj = json_decode($tmp);$dty = (time() + $obj->expires_in);$data['wx_access_token'] = $obj->access_token;$data['wx_expires_in'] = $dty;Db::name('app_public')->where('id', 1)->update( $data );return $obj->access_token;}else{return $config['wx_access_token'];}}/*** 模拟浏览器发送*/public function CURLSend($url, $method = 'get', $data = '') {$ch = curl_init(); //初始化$headers = array('Accept-Charset: utf-8');curl_setopt($ch, CURLOPT_URL, $url); //指定请求的URLcurl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method)); //提交方式curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //不验证SSLcurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //不验证SSLcurl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //设置HTTP头字段的数组curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible;MSIE5.01;Windows NT 5.0)'); //头的字符串curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_AUTOREFERER, 1); //自动设置header中的Referer:信息curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //提交数值curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //是否输出到屏幕上,true不直接输出$temp = curl_exec($ch); //执行并获取结果curl_close($ch);return $temp; //return 返回值}

然后根据openid获取本人信息

$url = 'https://api./cgi-bin/user/info?access_token='.$this->getAccessToken().'&openid=ocGkcxIF9cdyQdDVt5luGuARboHs&lang=zh_CN';$data_all = $this->CURLSend($url, 'get');object(stdClass)#52 (17) {["subscribe"]=>int(1)["openid"]=>string(28) "1111"["nickname"]=>string(3) "111"["sex"]=>int(1)["language"]=>string(5) "zh_CN"["city"]=>string(6) "111"["province"]=>string(6) "111"["country"]=>string(6) "中国"["headimgurl"]=>string(143) "111"["subscribe_time"]=>int(1579074211)["unionid"]=>string(28) "1111"["remark"]=>string(0) ""["groupid"]=>int(0)["tagid_list"]=>array(0) {}["subscribe_scene"]=>string(17) "ADD_SCENE_QR_CODE"["qr_scene"]=>int(0)["qr_scene_str"]=>string(6) "413911"}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。