萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> 微信自動獲取收貨地址api程序

微信自動獲取收貨地址api程序

微信公眾平台現在是越來越強大了,我們可以通過各種api接口來與平台對接獲取對應的數據了,下面來看一個由php實現的微信自動獲取收貨地址api程序,具體如下。


關於接口的說明我就不介紹了,在官方可以看到下面只看處理程序

public function get_address_api(){
 $APPID=C('APPID');
 $SCRETID=C('SCRETID');
 if (!isset($_GET['code']))
 {
 $backurl = $this->get_url();
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$APPID."&redirect_uri=".urlencode($backurl)."&response_type=code&scope=jsapi_address&state=123#wechat_redirect"; // snsapi_userinfo
Header("Location: $url");
exit;
}else
{
$code = $_GET['code'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$APPID."&secret=".$SCRETID."&code=".$code."&grant_type=authorization_code";
$re = file_get_contents($url);
$rearr = json_decode($re,true);
$backurl = $this->get_url();
$openid = $rearr['openid'];
$unionid = $rearr['unionid'];
$asstoken = $rearr['access_token'];
S('jsapi_address_token'.$openid,$asstoken,7200);
 
$data['appid']=$APPID;
$data['url']=$backurl;
$data['timestamp']=time();
$data['timestamp']= (string)($data['timestamp']);
$data['noncestr']=$this->getRandStr(10);
$data['accesstoken']=$asstoken;
 
foreach ($data as $k => $v)
 {
 $Parameters[$k] = $v;
 }
 //簽名步驟一:按字典序排序參數
 ksort($Parameters);
 $String = $this->formatBizQueryParaMap($Parameters, false);
$data['addrsign']=SHA1($String);
$this->assign('data',$data);
 
}
 
$this->siteDisplay('address_api');
 
}

copyright © 萬盛學電腦網 all rights reserved