Php version automatically obtains the Receiving address api usage example, api example
This example describes how to use the php api to automatically obtain the Receiving address. We will share this with you for your reference. The details are as follows:
The public platform is becoming more and more powerful. We can use various api interfaces to connect to the platform to obtain the corresponding data. Next we will look at an api program for Automatically Obtaining the shipping address implemented by php, the details are as follows.
I will not introduce the description of the interface. I can see it on the official website and only check 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 1: sort the parameter ksort ($ Parameters) by lexicographically; $ String = $ this-> formatBizQueryParaMap ($ Parameters, false); $ data ['addrsign'] = SHA1 ($ String); $ this-> assign ('data', $ data );} $ this-> siteDisplay ('address _ api ');}