예제 #1
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信息获取失败"
             }));
         }
     }
 }
예제 #2
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);
        }
        /// <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);
        }
예제 #4
0
        public static bool PushTemplate(PushTemplate data, PushTemplateLog template)
        {
            var result = false;

            try
            {
                using (var client = new WeiXinPushClient())
                {
                    var getResult = client.PushByTemplate(data, template);
                    getResult.ThrowIfException(true);
                    result = getResult.Result;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }