以下仅供参考:
/// <summary>
/// 微信支付后(必须在支付成功并回调后)获取用户UnionID mlj 20190912
/// </summary>
public static string GetUnionidAfterWxPay(string OPENID, string OUT_TRADE_NO)
{
string ACCESS_TOKEN = IOHelper.GetAccessToken();//小程序access_token
if (string.IsNullOrWhiteSpace(ACCESS_TOKEN))
{
return “”;
}
string MCH_ID = WxPayConfig.MCHID; //商户号
string requestUrl = string.Format(“https://api.weixin.qq.com/wxa/getpaidunionid?access_token={0}&openid={1}&mch_id={2}&out_trade_no={3}”, ACCESS_TOKEN, OPENID, MCH_ID, OUT_TRADE_NO);
JObject jobject;
try
{
jobject = JsonConvert.DeserializeObject<JObject>(WebHelper.GetRequestData(requestUrl, “Get”, “”));
}
catch (Exception e)
{
//Log.Error(“获取用户unionid异常”, e.ToString());
return “”;
}
if (jobject[“unionid”] == null)
{
//Log.Error(“获取用户unionid为空”, jobject.ToString());
return “”;
}
return jobject[“unionid”].ToString();
}