Php version of WeChat automatically get the Receiving address api usage example, api example

Source: Internet
Author: User
Tags openid

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 ');}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.