PHP version of the micro-letter automatically receive the address API usage Example _php instance

Source: Internet
Author: User
Tags openid

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.

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.