This article describes the PHP version of the micro-letter automatic access to receive address API usage. Share to everyone for your reference, specific as follows:
Micro-trust public platform is now more and more powerful, we can through a variety of API interface with the platform to get the corresponding data, the following to see a micro-letter implemented by PHP to automatically obtain the Receiving Address API program, specific as follows.
The description of the interface I will not introduce, in the official can see the following only look at the processing program.
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;
//Signature Step one: Sort parameters by Dictionary order ksort ($Parameters);
$String = $this->formatbizqueryparamap ($Parameters, false);
$data [' Addrsign ']=sha1 ($String);
$this->assign (' data ', $data);
} $this->sitedisplay (' Address_api ');
}
For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.