SEO外包平台,我们为您提供专业的企业网站SEO整站优化外包服务 SEO设置

SEO外包平台

专注于企业网站SEO整站优化外包服务

PHP微信生成具有参数的QR码

作者:八月      发布时间:2021-04-25      浏览量:0
控制器获得带有参数的QR代码和头(“Co

控制器获得带有参数的QR代码和

头(“Content-type:text/html;charset=utf-8”);定义(‘Token’,‘xxxx’);//令牌定义(‘app_ID’,‘wxxxxx’);//Developer appId,服务号得到定义(‘app_保密’,‘xxxxxxx’)/控制器获得QR代码公共函数qrcode($user_id with){include(‘wechat.php’);SET_TIME(30);//为了防止Access_令牌获取失败,死锁$wechatObj=新的WechatClass();echo‘QR代码地址:’。$wechatObj>;QrcodeCreate($USER_id);}//公众号群发推送公共函数推送消息($OpenID,$Text){包括(‘微信。(PHP‘);$wechatObj=新的WechatClass();$res[’Content‘]=$text;$arr=$OpenID;$data[’touser‘]=$arr;$data[’msgtype‘]=’text‘;$data[’text‘]=$res;$data=json_encode($data,JSON_UNESCAPED_Unicunicd);//var_dump($data);死;$row=$wechatj->;Message($data);Var_dump($row);}

<;?phpclass WechatClass{私有$令牌;私有$appId;私有$app秘密;私有$access Token;公共函数_structure(){$this->;Token=Token;$this->;appId=app_ID;$this->;appgt;appp_security;$this->;access Token=‘../access_Token’;如果(!file_services($this->;access Token)){$this->;AccessTokenGet();}}/*群发*/公共函数推送消息($群发){$access_群发=file_get_content($this->;access Token);$url=群发$Access_Token;$res=$this->JsonPost($url,$data);返回$res;}/*创建由QR代码@param-$qrcodeID传递的参数,$qrcodeType QR代码类型默认为临时QR代码@Reback-返回QR代码图片地址*/公共函数QrcodeCreate($qrcodeid,$qrcodeType=0){if($qrcodeType=0){$qrcodeType=‘qrcodeType=’qr_景致‘}}$temjson=‘{“届满_秒”:1800,“action_name”:“’.$qrcodeType.‘”,“action_info”:{“场景”:{“场景”:’.$qrcodeID.‘}};$access_Token=file_get_content($this->;Tokaccess en);$url=“https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=”.$access_token;$tunarr=json_decode($this->;jsonPost($url,$temjson),true);如果(@arraykey_ITES(‘票证’,$temarr)){返回‘https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=’.$tempArr[‘ticket’];}or{$this->;ErrorLogger(‘qrcode创建falied)。);$this->AccessTokenGet();$this->QrcodeCreate();}从微信服务器获取Access_TokenGet并写入配置文件*/私有函数AccessTokenGet(){$url=‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=’.$this->appID.‘&secret=’.$this->应用秘密;$temarr=json_decode(file_get_content($url),true);var_dump($temarr);如果(@Array_key_EXCES(‘Access_TOKEN’,$TEVERARR)){$temorWriter=fopen($this->;access Token,‘w’);fWriter($tunWriter,$temurarr[‘access_Token’]);}or{$this->;ErrorLogger(‘access_Token get falied’);Exit();}/*用户分组查询*/公共函数GroupsQuery(){$access_用户分组查询=file_get_content($this->;access Token);$url=用户分组查询$access_Token;$temarr=json_decode(file_get_content($url),true);if(@arraykey_ITES(‘group’,$temarr)){返回$temurr[‘group’];//返回数组格式的分组信息}or{$this->;ErrorLogger(‘组查询失败’)。);$this->;AccessTokenGet();$this->;GroupsQuery();}//Tool Function/*使用curl发布json数据*/CURLOPT_SSL_VERIFYPEER,CURLOPT_SSL_VERIFYHOST-use//CURLOPT_RETURRANSFER在执行https时不作为文件流返回,带有一个私有函数JsonPost($url,$jsonData){$curl=curl_init();Curl_setopt($curl,CURLOPT_URL,$url)curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);curl_setopt($curl,CURLOPT_POFIELDS,$jsonData);curl_setopt($curl,CLOPT_timeout,30);curl_setopt($curl,CURLOPT_RETURNER,1);curl_setopt($curl,CURLOPT_POSTFIELDS,$jsonData);curl_setopt($curl,CLOPT_timeout,30)如果(curl_errno($curl)){$this->;ErrorLogger(‘curl falied.curl_Error($curl));}curl_Close($curl);返回$Result;}/*错误日志记录*/私有函数ErrorLogger($errMsg){$logger=fopen(’./ErrorLog)。Txt‘,’a+‘;fwrite($logger,Date(’Y-m-d-H:i:s‘)。“Error Info:”。$errMsg.“\r\n”;}?>;