Access to OpenID and user information

Source: Internet
Author: User
Tags openid

How to Share

Access to user information through the interface is mainly divided into the following steps:

A. Obtaining the access_token of the public number

B. Get all users by querying all user OpenID interfaces.

String url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + access_token;

C, by acquiring user OpenID, and then using OpenID to obtain user data

D. Add user information to the database.

1. Parameterized queries and adding user information to database methods

Press CTRL + C to copy the codepublic void Addtodatabase (Userjson userInfo) {using (SqlConnection conn = new SqlConnection (connstrings ) {Conn. Open (); OpenID, subscribe, nickname, sex, language, city, province, country, Headimgurl, Subscribetime, remark= ""; String cmdtext = @ "INSERT into UserInfo values (@openid, @subscribe, @nickname, @sex, @language, @city, @prov Ince, @country, @headimgurl, @subscribetime, @remark) "; SqlCommand cmd = new SqlCommand (CMDTEXT, conn); Cmd. Parameters.addwithvalue ("@openid", Userinfo.openid); Cmd. Parameters.addwithvalue ("@subscribe", userinfo.subscribe); Cmd. Parameters.addwithvalue ("@nickname", userinfo.nickname); Cmd. Parameters.addwithvalue ("@sex", userinfo.sex); Cmd. Parameters.addwithvalue ("@language", userinfo.language); Cmd. Parameters.addwithvalue ("@city", userinfo.city); Cmd. ParameteRs. AddWithValue ("@province", userinfo.province); Cmd. Parameters.addwithvalue ("@country", userinfo.country); Cmd. Parameters.addwithvalue ("@headimgurl", Userinfo.headimgurl); Cmd. Parameters.addwithvalue ("@subscribetime", userinfo.subscribe_time); Cmd. Parameters.addwithvalue ("@remark", Userinfo.remark); int res = cmd. ExecuteNonQuery (); } }Press CTRL + C to copy the code

2. Get user data via OpenID call interface

 Publicvoid GetUserInfo (StringOpenID) {String url ="https://api.weixin.qq.com/cgi-bin/user/info?access_token= " " &lang=zh_cnstring result = HttpGet (URL, ); // JSON deserialized to object JavaScriptSerializer serializer = new JavaScriptSerializer (); Userjson UserInfo = serializer. Deserialize<userjson> 

3. Get all OpenID

  String url ="https://api.weixin.qq.com/cgi-bin/user/get?access_token=                 "+ Access_token; string openidlist = HttpGet (URL, ); List<string> list = new List<string> (); JavaScriptSerializer serializer = new JavaScriptSerializer (); Userlistjsonresult result = serializer. Deserialize<userlistjsonresult>// Userlistjsonresult result = Jsonhelper.getobjfromjson<userlistjsonresult> ( openidlist)               

Access to OpenID and user information

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.