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

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

2017-02-04 09:41 381 查看
#region 方法 GetQiyConvertToOpenid(string accesstoken, string strUserId)  userid转换成openid接口

    /// <summary>

    /// 

    /// </summary>

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

    /// <param name="strUserId"></param>

    /// <returns></returns>

    public string GetQiyConvertToOpenid(string accesstoken, string strUserId)

    {

        TWeixinHelper weihelper = new TWeixinHelper();

        string weixin = "{\"userid\": \"" + strUserId + "\", \"agentid\":\"1\"}";

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

       string strOpenId = "";

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

       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)

           {

               strOpenId = match.Groups["openid"].Value;

           }

       }

       return strOpenId;

    }

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