A net intern's first blog post

Source: Internet
Author: User
Tags openid

To work fast two months, growth of course, there are some, but there are a lot of bad, a lot of things may not be in-depth understanding, can only do some simple functions, and then sometimes may be less efficient, the head more like disorderly thinking.

Keep a record of your work and study every day. Of course, the goal is to focus on the implementation of all the functions of the stage, performance, and so on later or the master to solve and raise the point and self-growth for some time.

New project, want me to do a personal center then in understanding and QQ third-party login now do some of the incomplete implementations only did three steps

Transfer to login page via link

Then log on to the success callback page to get code

String url = "Https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + AppID + "&redirect_uri=" + Redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect";

And then get Access_token by code.

String access_token = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + AppID + "&secret=" + Appsecret + " &code= "+ code +" &grant_type=authorization_code ";

Finally Access_token get personal information

String Getdate = "https://api.weixin.qq.com/sns/userinfo?access_token=" + Tokendate.access_token + "&openid=" + Tokendate.openid + "&LANG=ZH_CN";

HttpClient client = new HttpClient ();
String json = client. Getstringasync (Access_token). Result;

The data obtained is, of course, also to be deserialized next to the little master proposed to create an entity corresponding to the returned data format and then read directly as follows

String Getjson = client. Getstringasync (Getdate). Result;

Backdata da = jsonconvert.deserializeobject<backdata> (Getjson);

The Backdata entity is

public class Backdata
{
<summary>
User Nickname
</summary>
String Nickname {get; set;}
<summary>
Average user sex, 1 for men, 2 for women
</summary>
int sex {get; set;}
<summary>
Provinces
</summary>
String province {get; set;}
<summary>
User picture
</summary>
String Headimgurl {get; set;}
<summary>
City
</summary>
String City {get; set;}
<summary>
Countries
</summary>
String Country {get; set;}
<summary>
Unified identity
</summary>
int Unionid {get; set;}
}

It is also possible to deserialize through the following

Jobject Jo = (jobject) jsonconvert.deserializeobject (reader. ReadToEnd ());
string zo = jo["Data" ["forecast"]. ToString ();

A net intern's first blog post

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.