This article mainly introduces the PHP version of the automatic acquisition address API usage, combined with instance form analysis of PHP API interface call and use skills, the need for friends can refer to the following
Public platform is now more and more powerful, we can through a variety of API interface to get the corresponding data from the platform, the following is a PHP implementation of the automatic Acquisition Address API program, as follows.
The description of the interface I do not introduce, in the official can see the following only to see 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: sorted by dictionary order parameter Ksort ($Parameters); $String = $this->formatbizqueryparamap ($Parameters, false); $data [' Addrsign ']=sha1 ($String); $this->assign (' data ', $data); } $this->sitedisplay (' Address_api ');}
Summary: The above is the entire content of this article, I hope to be able to help you learn.