1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 生成微信公众号二维码(用户扫码关注公众号)

生成微信公众号二维码(用户扫码关注公众号)

时间:2022-08-04 05:38:26

相关推荐

生成微信公众号二维码(用户扫码关注公众号)

1、token 文件

/*** https://mp./advanced/advanced?action=dev&t=advanced/dev&token=11111&lang=zh_CN* wechat php test* 验证回调地址 token* 公众号--> 开发 ---> 服务器设置---->服务验证token*///服务器地址(URL)//http://域名/wx/wx_token.php//定义TOKEN密钥define("TOKEN","loginzf");$wechatObj = new wechatCallbackapiTest();$wechatObj->valid();class wechatCallbackapiTest{public function valid(){$echoStr = $_GET["echostr"];//valid signature , optionif($this->checkSignature()){echo $echoStr;exit;}}private function checkSignature(){$signature = $_GET["signature"];$timestamp = $_GET["timestamp"];$nonce = $_GET["nonce"];$token = TOKEN;$tmpArr = array($token, $timestamp, $nonce);sort($tmpArr);$tmpStr = implode( $tmpArr );$tmpStr = sha1( $tmpStr );if( $tmpStr == $signature ){return true;}else{return false;}}}

2、 配置文件 conf.php

header("Content-type: text/html; charset=utf-8");// 开发者ID(AppID)$appid="";//开发者密码(AppSecret)$appsecret="";// 公众号--->开发----> 接口权限---> 网页服务---> 网页授权 ---> 修改 【按照说明操作】// 域名/wx 服务器 网页授权域名 不加 http:// 2处域名要一致//https://mp./cgi-bin/settingpage?t=setting/function&action=function&token=11111&lang=zh_CN$re_url=urlencode("http://域名/wx/wx_callback.php");//$state=123; // 自定义标识$scope="snsapi_userinfo"; //应用授权作用域//$scope="snsapi_base"; // 不弹出授权页面,直接跳转,只能获取用户openidinclude "curl.php"; ///xuey/p/8461622.html 引入curl 函数

3、获取开发者的 access_token.php

// https://mp./wiki?t=resource/res_main&id=mp1421140183include "conf.php";// 获取 access_tokenif(isset($_COOKIE['access_token'])){$access_token=$_COOKIE['access_token'];}else{$token_url="https://api./cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;$json_return=curl_url($token_url);$json_info = json_decode($json_return, true);$access_token =$json_info["access_token"];setcookie('access_token',$access_token,86400,'/'); //此步骤可以省略,也可自定义存储 时间}

4、生成公众号二维码 wx_img.php

//生成带参数的二维码 ---- 扫码进入进入公众号// https://mp./wiki?t=resource/res_main&id=mp1443433542function wx_img(){include "access_token.php";$qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 10000}}}';$url = "https://api./cgi-bin/qrcode/create?access_token=".$access_token;$result =https_post($url,$qrcode);$jsoninfo = json_decode($result, true);$ticket = $jsoninfo["ticket"];$url_ticket="https://mp./cgi-bin/showqrcode?ticket=$ticket";echo "<img src=".$url_ticket.">";}wx_img();

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