Пример #1
0
 public static bool RefreshAccessToken(DateTime dt)
 {
     lock (oLock)
     {
         if (dt < _access_token.GetData)
         {
             //已经更新过了
             return(true);
         }
         WFHttpWebResponse WebResponse = new WFHttpWebResponse();
         string            url         = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=";//APPID&secret=APPSECRET";
         url += appID;
         url += "&secret=";
         url += appsecret;
         HttpWebResponse            hr = WebResponse.CreateGetHttpResponse(url);
         DataContractJsonSerializer s  = new DataContractJsonSerializer(typeof(BaseJsonData));
         MemoryStream stream           = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(WebResponse.Content));
         BaseJsonData calldata         = (BaseJsonData)s.ReadObject(stream);
         if (calldata.access_token != null)//获取成功
         {
             _access_token.GetData    = DateTime.Now;
             _access_token.value      = calldata.access_token;
             _access_token.expires_in = calldata.expires_in;
         }
     }
     return(true);
 }
Пример #2
0
        public static string GetSerIP()
        {
            WFHttpWebResponse WebResponse = new WFHttpWebResponse();
            string            url         = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=";//APPID&secret=APPSECRET";

            url += _access_token.value;
            HttpWebResponse            hr = WebResponse.CreateGetHttpResponse(url);
            DataContractJsonSerializer s  = new DataContractJsonSerializer(typeof(BaseJsonData));
            MemoryStream stream           = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(WebResponse.Content));
            BaseJsonData calldata         = (BaseJsonData)s.ReadObject(stream);

            if (calldata.ip_list != null)//获取成功
            {
                return(calldata.ip_list);
            }
            else
            {
                return(null);
            }
        }