PHP Micro-trust public platform of micro-letter Web Landing Authorization Example _php instance

Source: Internet
Author: User
Tags oauth openid

This article describes the PHP version of micro-trust public platform of micro-letter Web landing authorization. Share to everyone for your reference, specific as follows:

Micro-credit public platform to achieve the implementation of micro-letter Web Landing Authorization development is very simple, because the official reference program, the following small series to see a webmaster based on the official reference to do a Web landing authorization example, we can see.

File 1:index.php

Switch to their own interface information
$appid = ' XXXXX ';
Header (' location:https://open.weixin.qq.com/connect/oauth2/authorize?appid= '. $appid. ' &redirect_uri=127.0.0.1/oauth.php&response_type=code&scope=snsapi_userinfo&state=123& Connect_redirect=1#wechat_redirect ');

Parameters Whether you must Description
AppID Is Unique identification of the public number
Redirect_uri Is Callback link address that is redirected after authorization, use UrlEncode to process the link
Response_type Is return type, please fill in the code
Scope Is Application authorization scope, Snsapi_base (not pop-up authorization page, direct jump, can only obtain user OpenID), Snsapi_userinfo (pop-up authorization page, can get nickname, sex, location via OpenID). And, even in the event of not paying attention, can obtain the information as long as the user authorizes.
State Whether After redirection, the state parameter is taken, and the developer can fill in the a-za-z0-9 parameter values
#wechat_redirect Is This parameter must be taken either directly or on page 302 redirection

File Two: oauth.php, the code is as follows:

<?php $code = $_get[' code '];
$state = $_get[' state '];
Switch to their own interface information $appid = ' XXXXX ';
$appsecret = ' XXXXX ';
if (Emptyempty ($code)) $this->error (' authorization failed '); $token _url = ' https://api.weixin.qq.com/sns/oauth2/access_token?appid= '. $appid. ' &secret= '. $appsecret. ' &code= '. $code. '
&grant_type=authorization_code ';
$token = Json_decode (file_get_contents ($token _url));
 if (Isset ($token->errcode)) {echo '  

Parameters Describe
Openid Unique identification of the user
Nickname User Nickname
Sex The user's sex, the value of 1 o'clock is male, the value of 2 o'clock is female, the value of 0 o'clock is unknown
Province The province in which the user's personal data is filled
City The city where the ordinary user's personal data fills in
Country Countries, such as China for CN
Headimgurl User Avatar, the last value represents the size of the square head (there are 0, 46, 64, 96, 132 value Optional, 0 represents 640*640 square avatar), the user does not have the Avatar when the item is empty.
Privilege User privileged information, JSON array, such as micro-SIM user (chinaunicom)
Unionid The field will only appear if the user binds the public number to the micro-trust Open platform account. See: Get User's personal information (Unionid mechanism)

To this page landing authorization development function is done, if you want to get the user's basic information we need to see another example, in the official instructions that everyone can search for themselves oh.

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.