获取UnionID
如果你需要多平台管理你的微信用户,那么unionID将成为你唯一的选择。
获取UnionID有两种方式
方式一、通过获取用户信息中来获取UnionID
/// <summary>
/// 获取unionID
/// </summary>
/// <param name="access_token">基础access_token</param>
/// <param name="openId">用户openID</param>
/// <returns>返回openId对应的unionID</returns>
public static string getUnionID(int wxid, string openId)
{
CRMComm wxCom = new CRMComm();
string errMsg = "";
string unionId = "";
string url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + wxCom.GetAccessToken(wxid, out errMsg) + "&openid=" + openId + "&lang=zh_CN";
string result = RequestHelper.GetAcc(url);
result = "[" + result + "]";
JArray cardResult = (JArray)JsonConvert.DeserializeObject(result);
JObject cardObj = (JObject)cardResult[0];
if (cardObj["unionid"] != null)
{
unionId = cardObj["unionid"].ToString();
}
return unionId;
}
方式二、通过网页授权的方式来获取uniodID
注意!!!注意!!!
获取unionID是有前提条件的,需要你将公众号绑定到微信平台https://open.weixin.qq.com/。