本文實例為大家分享了php獲取微信共享收貨地址的具體代碼,供大家參考,具體內容如下
必須是微信授權目錄 我直接放到了根目錄 其他目錄無效
/* * 在執行此操作之前 首先判斷您是否開通了 微信支付功能 審核通過后均可使用一下代碼 * 1、設置微信公眾平臺網頁授權 域名 www.abc.com * 2、設置下面的 “ 微信參數 ” * 3、把 當前文件 index.php 放入根目錄 * 4、用微信訪問http://www.abc.com/index.php 就可以了 切記一定是微信哦 ?php//微信參數$appId = ********* $appSecret = ***************** //獲取get參數$code = $_GET[ code //獲取 code$redirect_uri = http:// .$_SERVER[ HTTP_HOST ].$_SERVER[ REQUEST_URI $url = https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appId redirect_uri= .urlencode($redirect_uri). response_type=code scope=jsapi_address state=cft#wechat_redirect if(empty($code)){ header( location: $url //獲取 access_token$access_token_url = https://api.weixin.qq.com/sns/oauth2/access_token?appid= .$appId. secret= .$appSecret. code= .$code. grant_type=authorization_code $access_token_json = getUrl($access_token_url);$access_token = json_decode($access_token_json,true);
//===============下面數組 生成SING 使用=====================$Parameters[ appid ] = $appId;$Parameters[ url ] = $redirect_uri;$Parameters[ timestamp ] = $timestamp $Parameters[ noncestr ] = $nonceStr $Parameters[ accesstoken ] = $access_token[ access_token // 生成 SING$addrSign = genSha1Sign($Parameters);
meta charset= utf-8 / meta id= viewport name= viewport content= width=device-width; initial-scale=1.0; maximum-scale=1; user-scalable=no; / /head script language= javascript function getaddr(){ WeixinJSBridge.invoke( editAddress ,{ appId : ?php echo $appId;? , //公眾號名稱,由商戶傳入 timeStamp : ?php echo $timestamp;? , //時間戳 這里隨意使用了一個值 nonceStr : ?php echo $nonceStr;? , //隨機串 signType : SHA1 , //微信簽名方式:sha1 addrSign : ?php echo $addrSign;? , //微信簽名 scope : jsapi_address },function(res){ if(res.err_msg == edit_address:ok ){ document.getElementById( showAddress ).innerHTML= 收件人: +res.userName+ 聯系電話: +res.telNumber+ 收貨地址: +res.proviceFirstStageName+res.addressCitySecondStageName+res.addressCountiesThirdStageName+res.addressDetailInfo+ 郵編: +res.addressPostalCode; else{ alert( 獲取地址失敗,請重新點擊 /script body style section.content{padding:10px 12px;} section .showaddr{border:1px dashed #C9C9C9;padding:10px 10px 15px;margin-bottom:20px;color:#666666;font-size:12px;text-align:center;} section .showaddr strong{font-weight:normal;color:#9900FF;font-size:26px;font-family:Helvetica;} /style section >以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持php 。
您可能感興趣的文章:在云html' target='_blank'>虛擬主機部署thinkphp5項目步驟詳解
PHPCrawl爬蟲庫實現抓取酷狗歌單的方法示例講解
PHP實現生成模糊圖片的方法示例講解
以上就是php獲取微信共享收貨地址的方法講解的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答