第一步:获取授权码信息
my.getAuthCode({
scopes: 'auth_base',
success: (res) => {
// res.authCode
//发送授权码到服务后台进行解析
}
});
第二步:解析授权码(SDK:https://download.csdn.net/download/qq_36894527/12875709)
////// 获取支付宝用户id /// /// 小程序授权码 /// appid /// 应用私钥,和应用公钥匹配 在密钥生产器中可见 /// 支付宝公钥(区别于应用公钥),开放平台中接口加签方式中可见 ///public static string GetUserID(string auth_code, string app_id, string merchant_private_key, string alipay_public_key) { string result = ""; try { IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app_id, merchant_private_key, "json", "1.0", "RSA2", alipay_public_key, "GBK", false); AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); request.GrantType = "authorization_code"; request.Code = auth_code; request.RefreshToken = ""; AlipaySystemOauthTokenResponse response = client.Execute(request); JObject jobj = (JObject)JsonConvert.DeserializeObject(response.Body); JObject jk = (JObject)jobj["alipay_system_oauth_token_response"]; if (jk.Property("code") == null) { string user_id = jobj["alipay_system_oauth_token_response"]["user_id"].ToString(); result = ReturnInfo.ListReturn("S", "", user_id); } else { string msg = jobj["alipay_system_oauth_token_response"]["msg"].ToString(); result = ReturnInfo.ListReturn("E", msg, ""); } } catch (Exception ex) { result = ReturnInfo.ListReturn("E", ex.Message, ""); } return result; }



