コード例 #1
0
ファイル: BaseAccessToken.cs プロジェクト: hkmujj/zllinmitu
 protected static T ReadToken <T>(string url, string modelName, T token) where T : BaseAccessToken
 {
     token = WeUtil.GetFromUri(url, modelName, token, true);
     token.SetExpireTime();
     //SaveToken(token);
     return(token);
 }
コード例 #2
0
        public static List <string> GetServerIpList()
        {
            string url    = GetCorpUrl(WeCorpConst.IP_LIST, WeixinSettings.Current.CorpUserManagerSecret);
            var    result = WeUtil.GetFromUri <WeIpList>(url);

            return(result.IpList);
        }
コード例 #3
0
        public static bool VerifySignature(string token, string timeStamp, string nonce,
                                           string msgEncrypt, string sigture)
        {
            string hash = WeUtil.CreateSignature(token, timeStamp, nonce, msgEncrypt);

            return(hash == sigture);
        }
コード例 #4
0
        public static List <string> GetServerIpList()
        {
            string url    = GetUrl(WeConst.IP_LIST);
            var    result = WeUtil.GetFromUri <WeIpList>(url);

            return(result.IpList);
        }
コード例 #5
0
ファイル: QRCodeInputData.cs プロジェクト: hkmujj/zllinmitu
        public QRCodeResult CreateTick()
        {
            QRCodeResult result = new QRCodeResult();
            string       url    = WeUtil.GetUrl(WeConst.QR_CREATE_URL);

            result = WeUtil.PostToUri(url, this.WriteJson(WeConst.WRITE_SETTINGS), result);
            return(result);
        }
コード例 #6
0
        //将企业号回复用户的消息加密打包
        // @param sReplyMsg: 企业号待回复用户的消息,xml格式的字符串
        // @param sTimeStamp: 时间戳,可以自己生成,也可以用URL参数的timestamp
        // @param sNonce: 随机串,可以自己生成,也可以用URL参数的nonce
        // @param sEncryptMsg: 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串,
        //						当return返回0时有效
        // return:成功0,失败返回对应的错误码
        public static EncodeReplyMessage EncryptMsg(int appId, string replyMsg,
                                                    string timeStamp, string nonce)
        {
            Tuple <string, string> token = WeixinSettings.Current.GetToken(appId);
            string raw = Cryptography.AesEncrypt(replyMsg, token.Item2, WeixinSettings.Current.AppId);

            return(WeUtil.EncodeReplyMessage(timeStamp, nonce, token.Item1, raw));
        }
コード例 #7
0
        internal static CorpAuthToken GetToken(int appId, string code)
        {
            //var current = WeixinSettings.Current;
            string url = string.Format(ObjectUtil.SysCulture, WeCorpConst.AUTH_ACCESS_TOKEN,
                                       CorpAccessToken.GetTokenWithAppId(appId), code, appId);

            return(WeUtil.GetFromUri <CorpAuthToken>(url));
        }
コード例 #8
0
        public static DownloadMediaData DownloadFile(string secret, string mediaId)
        {
            TkDebug.AssertArgumentNullOrEmpty(secret, "secret", null);
            TkDebug.AssertArgumentNullOrEmpty(mediaId, "mediaId", null);

            string url = string.Format(ObjectUtil.SysCulture, WeCorpConst.DOWNLOAD_URL,
                                       CorpAccessToken.GetTokenWithSecret(secret), mediaId);

            return(WeUtil.InternalDownloadData(url));
        }
コード例 #9
0
 public string ConvertToString(object value, WriteSettings settings)
 {
     try
     {
         DateTime date = (DateTime)value;
         return(WeUtil.ToCreateTime(date).ToString(ObjectUtil.SysCulture));
     }
     catch
     {
         return(DefaultValue);
     }
 }
コード例 #10
0
 public object ConvertFromString(string text, ReadSettings settings)
 {
     try
     {
         int value = int.Parse(text, ObjectUtil.SysCulture);
         return(WeUtil.ToDateTime(value));
     }
     catch
     {
         return(DateTime.Now);
     }
 }
コード例 #11
0
        public static MediaId UploadFile(string secret, MediaType mediaType,
                                         string fileName, byte[] fileData)
        {
            TkDebug.AssertArgumentNullOrEmpty(secret, "secret", null);
            TkDebug.AssertArgumentNullOrEmpty(fileName, "fileName", null);
            TkDebug.AssertArgumentNull(fileData, "fileData", null);

            int    maxLength = GetMaxLength(mediaType);
            string url       = string.Format(ObjectUtil.SysCulture, WeCorpConst.UPLOAD_URL,
                                             CorpAccessToken.GetTokenWithSecret(secret),
                                             mediaType.ToString().ToLower(ObjectUtil.SysCulture));

            return(WeUtil.InternalUploadFile(mediaType, fileName, fileData, maxLength, url));
        }
コード例 #12
0
        private static JsAccessToken CreateToken()
        {
            string url;

            if (WeixinSettings.Current.Mode == WeixinMode.Normal)
            {
                url = WeUtil.GetUrl(WeConst.JS_TICKET);
            }
            else
            {
                url = WeCorpUtil.GetCorpUrl(WeCorpConst.JS_TICKET, WeixinSettings.Current.CorpUserManagerSecret);
            }
            JsAccessToken token = ReadToken(url, WeConst.JS_MODE, new JsAccessToken());

            SaveToken(token);
            return(token);
        }
コード例 #13
0
        public OutputData DoAction(IInputData input)
        {
            if (!input.IsPost)
            {
                if (WeUtil.CheckSignature(input.QueryString[QueryStringConst.QS_SIGNATURE],
                                          input.QueryString[QueryStringConst.QS_TIMESTAMP],
                                          input.QueryString[QueryStringConst.QS_NONCE]))
                {
                    return(OutputData.Create(input.QueryString[QueryStringConst.QS_ECHO_STR]));
                }
                return(OutputData.Create("验名错误"));
            }
            else
            {
                ReceiveMessage  message = input.PostObject.Convert <ReceiveMessage>();
                BaseSendMessage result  = WeixinToolkitSettings.Current.NormalReply(message);
                WeixinToolkitSettings.Current.Log(message);

                if (result != null)
                {
                    string encodeType = input.QueryString[QueryStringConst.QS_ENCODE_TYPE]
                                        .Value <string>(QueryStringConst.NORMAL_MSG);
                    if (encodeType == QueryStringConst.NORMAL_MSG)
                    {
                        return(OutputData.CreateToolkitObject(result));
                    }
                    else
                    {
                        EncodeReplyMessage reply = WeUtil.EncryptMsg(result.ToXml(),
                                                                     input.QueryString[QueryStringConst.QS_TIMESTAMP],
                                                                     input.QueryString[QueryStringConst.QS_NONCE]);
                        return(OutputData.CreateToolkitObject(reply));
                    }
                }
                else
                {
                    return(OutputData.Create(string.Empty));
                }
            }
        }