PHP WeChat automatically get the delivery address API usage examples

Source: Internet
Author: User
Tags openid
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.

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.