基本参数
- 获取
appid
及secret
- 获取登录凭证code
登陆你的微信小程序在开发设置里面可以直接看到appid和secret

获取登录凭证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| uni.login({ success: res => { var code=res.code; if(code) { uni.request({ url: that.apiRoot + '/Fly_Fp/Fly_Fp_ApplyFor/getuseropenid', method: 'POST', data: { ...that.auth, data: res.code }, success: (res) => { var openId = res.data; } }) } } });
|
请求微信API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
public string ProcessRequest(string code, string iv, string encryptedData) { string Appid = "wx****************"; string Secret = "****************************"; string grant_type = "authorization_code"; string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Appid + "&secret=" + Secret + "&js_code=" + code + "&grant_type=" + grant_type; string type = "utf-8"; var resData = this.GetUrltoHtml(url, type); return resData; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public string GetUrltoHtml(string Url, string type) { try { System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type))) { return reader.ReadToEnd(); } } catch (System.Exception ex) { return ex.Message; } }
|