Beispiel #1
0
        /// <summary>
        /// 获取素材总数
        /// </summary>
        public GetMaterialCountResultModel GetMaterialCount(string accessToken)
        {
            var data = new WeChatDataModel();

            data.SetValue("access_token", accessToken);
            string   url          = $"{Config.WeChatAPIUrl}cgi-bin/material/get_materialcount?{data.ToUrlParams()}";
            string   weChatResult = WeChatHttpManager.Get(url);
            JsonData jsonData     = JsonMapper.ToObject(weChatResult);

            if (WeChatPublicNumberErrorHelper.IsError(jsonData))
            {
                throw WeChatPublicNumberErrorHelper.GetWeChatException(jsonData);
            }
            var result = weChatResult.JsonToObject <GetMaterialCountResultModel>();

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 获取微信IP地址
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public List <string> GetWeChatIPAddress(string accessToken)
        {
            var data = new WeChatDataModel();

            data.SetValue("access_token", accessToken);
            string   url          = $"{Config.WeChatAPIUrl}cgi-bin/getcallbackip?{data.ToUrlParams()}";
            string   weChatResult = WeChatHttpManager.Get(url);
            JsonData jsonData     = JsonMapper.ToObject(weChatResult);

            if (WeChatPublicNumberErrorHelper.IsError(jsonData))
            {
                throw WeChatPublicNumberErrorHelper.GetWeChatException(jsonData);
            }
            JsonData ipList = jsonData["ip_list"];
            var      result = new List <string>();

            for (var i = 0; i < ipList.Count; i++)
            {
                result.Add(ipList[i].ToString());
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// 获取临时素材
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="mediaID"></param>
        /// <param name="isVideo"></param>
        public void GetTemporaryMaterial(string accessToken, string mediaID, bool isVideo = false)
        {
            var data = new WeChatDataModel();

            data.SetValue("access_token", accessToken);
            data.SetValue("media_id", mediaID);
            string url = $"{Config.WeChatAPIUrl}cgi-bin/media/get?{data.ToUrlParams()}";

            if (isVideo)
            {
                string   weChatResult = WeChatHttpManager.Get(url);
                JsonData jsonData     = JsonMapper.ToObject(weChatResult);
                if (WeChatPublicNumberErrorHelper.IsError(jsonData))
                {
                    throw WeChatPublicNumberErrorHelper.GetWeChatException(jsonData);
                }
            }
            else
            {
                StreamReader weChatResult = WeChatHttpManager.GetStreamReader(url);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取AccessToken
        /// </summary>
        /// <returns>OpenID</returns>
        public AccessTokenResultModel GetAccessToken()
        {
            var data = new WeChatDataModel();

            data.SetValue("appid", Config.APPID);
            data.SetValue("secret", Config.APPSECRET);
            data.SetValue("grant_type", "client_credential");
            string   url          = $"{Config.WeChatAPIUrl}cgi-bin/token?{data.ToUrlParams()}";
            string   weChatResult = WeChatHttpManager.Get(url);
            JsonData jsonData     = JsonMapper.ToObject(weChatResult);

            if (WeChatPublicNumberErrorHelper.IsError(jsonData))
            {
                throw WeChatPublicNumberErrorHelper.GetWeChatException(jsonData);
            }
            var accessToken = new AccessTokenResultModel
            {
                AccessToken = jsonData["access_token"].ToString(),
                ExpiresIn   = Convert.ToInt32(jsonData["expires_in"].ToString())
            };

            return(accessToken);
        }