Beispiel #1
0
        private static void GetTokenFromWeb()
        {
            try
            {
                string tokenJson = SecurityHttpUtil.DealGet(QYWeiXinObj.UrlTemplate.Token);
                if (string.IsNullOrEmpty(tokenJson) == false)
                {
                    JToken errcode, access_token, expires_in;

                    JObject jObj = JObject.Parse(tokenJson);
                    if (jObj.TryGetValue("errcode", out errcode) && jObj.TryGetValue("access_token", out access_token) && jObj.TryGetValue("expires_in", out expires_in))
                    {
                        JValue errcodeV, access_tokenV, expires_inV;
                        errcodeV      = errcode as JValue;
                        access_tokenV = access_token as JValue;
                        expires_inV   = expires_in as JValue;

                        if (errcodeV != null && (long)errcodeV.Value == 0)
                        {
                            QYWeiXinObj.SetCahce((string)access_tokenV.Value, (long)expires_inV.Value);
                        }
                        else
                        {
                            Logger.Write(LogLevel.Error, "QYWeiXin:GetToken from api is error,there is not correct reponse!" + tokenJson);
                        }
                    }
                    else
                    {
                        Logger.Write(LogLevel.Error, "QYWeiXin:GetToken from api is error,there is not correct response!" + tokenJson);
                    }
                }
                else
                {
                    Logger.Write(LogLevel.Error, "QYWeiXin:GetToken from api is error,there is no reponse!");
                }
            }
            catch (Exception ex)
            {
                Logger.Write(LogLevel.Error, "QYWeiXin:GetToken is error!" + ex.ToString());
            }
        }
Beispiel #2
0
 private static void SendMsgFromWeb(string postData)
 {
     try
     {
         string ret = SecurityHttpUtil.DealPost(QYWeiXinObj.Url.SendMsg, postData);
         if (string.IsNullOrEmpty(ret) == false)
         {
             JToken  errcode, errmsg;
             JObject jObj = JObject.Parse(ret);
             if (jObj.TryGetValue("errcode", out errcode) && jObj.TryGetValue("errmsg", out errmsg))
             {
                 JValue errcodeV, errmsgV;
                 errcodeV = errcode as JValue;
                 errmsgV  = errmsg as JValue;
                 if (errcodeV != null && (long)errcodeV.Value == 0)
                 {
                     Logger.Write(LogLevel.Debug, "QYWeiXin:SendMsg from api is ok!" + ret);
                 }
                 else
                 {
                     Logger.Write(LogLevel.Error, "QYWeiXin:SendMsg from api is error,there is not correct reponse!" + ret);
                 }
             }
             else
             {
                 Logger.Write(LogLevel.Error, "QYWeiXin:SendMsg from api is error,there is not correct reponse!" + ret);
             }
         }
         else
         {
             Logger.Write(LogLevel.Error, "QYWeiXin:SendMsg from api is error,there is no reponse!");
         }
     }
     catch (Exception ex)
     {
         Logger.Write(LogLevel.Error, "QYWeiXin:SendMsg is error!" + ex.ToString());
     }
 }