您的位置:首页 > 移动开发 > 微信开发

net/c# 微信企业号 userid转换成openid接口

2017-02-04 09:45 441 查看
#region 方法 GetQiyConvertToUserid(string accesstoken, string strOpenId)  openid转换成userid接口

    /// <summary>

    /// 

    /// </summary>

    /// <param name="accesstoken"></param>

    /// <param name="strOpenId"></param>

    /// <returns></returns>

    public string GetQiyConvertToUserid(string accesstoken, string strOpenId)

    {

        TWeixinHelper weihelper = new TWeixinHelper();

        string weixin = "{\"openid\": \"" + strOpenId + "\"}";

        string to = weihelper.GetPage("https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid?access_token=" + accesstoken, weixin);

        string strUserId = "";

        string strCode = @"\""userid\"":\s*""(?'userid'[^""]*)""";

        Regex regex = new Regex(strCode, RegexOptions.IgnoreCase);

        if (regex.IsMatch(to))

        {

            MatchCollection matches = regex.Matches(to);

            StringBuilder stringBuilder = new StringBuilder();

            foreach (Match match in matches)

            {

                strUserId = match.Groups["userid"].Value;

            }

        }

        return strUserId;

    }

    #endregion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: