Exemple #1
0
        /// <summary>
        /// 获取微信公众号名称
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private string GetWXName(string value)
        {
            var resultStr = "";

            if (string.IsNullOrWhiteSpace(value))
            {
                return("");
            }

            var splitList = value.Split(',');

            using (var client = new WeiXinPushClient())
            {
                var clientResult = client.SelectWxConfigs();
                if (clientResult.Success)
                {
                    var wxOpenList = clientResult.Result.Where(t => (t.Type == "WX_Open") && !string.IsNullOrWhiteSpace(t.channel))
                                     ?.Select(t => new { t.name, t.channel });
                    var containsList = wxOpenList?.Where(t => splitList.Contains(t.channel))?.Select(a => a.name)?.ToList();
                    if (containsList?.Count() > 0)
                    {
                        resultStr = string.Join(",", containsList);
                    }
                }
            }
            return(resultStr);
        }
Exemple #2
0
 public JsonResult GetAppIdList()
 {
     using (var client = new WeiXinPushClient())
     {
         var result = client.SelectWxConfigs();
         if (result.Success && result.Result != null)
         {
             return(Json(
                        new
             {
                 Code = 1,
                 Data = result.Result.Where(g => g.Type == "WX_APP").Select(g => new
                 {
                     AppId = g.appId,
                     Name = g.name
                 })
             }));
         }
         else
         {
             return(Json(new
             {
                 Code = 0,
                 Info = "APPID信息获取失败"
             }));
         }
     }
 }
        /// <summary>
        /// 创建微信 accesstoken
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appsecret"></param>
        /// <returns></returns>
        private static token CreateToken(string appkey, string appsecret)
        {
            token token    = new token();
            int   platform = -1;

            using (var client = new WeiXinPushClient())
            {
                var response = client.SelectWxConfigs();
                if (response.Success && response.Result != null)
                {
                    var first = response.Result
                                .FirstOrDefault(x => string.Equals(x.appKey, appkey, StringComparison.OrdinalIgnoreCase));
                    if (first != null)
                    {
                        platform = first.platform;
                    }
                }
            }
            var access_token = webRequestGet("https://wx.tuhu.cn/packet/test?platform=" + platform);

            token = JsonConvert.DeserializeObject <token>(access_token);
            if (token != null && !string.IsNullOrWhiteSpace(token.access_token))
            {
                token.CreateTime = DateTime.Now;
            }
            else
            {
                throw new Exception("获取token失败");
            }
            return(token);
        }