Exemplo n.º 1
0
        public async Task <string> Post(string signature, string timestamp, string nonce, string echostr)
        {
            if (!CheckSignature.Check(signature, timestamp, nonce, _token))
            {
                // 校验失败,不会对此作任何处理
                return("");
            }
            var notifyContent = Request.Body.ToStr(Encoding.UTF8);
            var dict          = XmlUtil.FromXml(notifyContent);

            if (dict["Event"].ToString() != WechatConstants.MESSAGE_SUBSCRIBE)
            {
                //不会对此作任何处理
                return("");
            }
            var toUserName   = dict["FromUserName"].ToString();
            var fromUserName = dict["ToUserName"].ToString();
            var dateTime     = dict["CreateTime"].ToString();

            var token = await _weChatHelper.GetAccessToken();

            var content = await _weChatHelper.GetMaterial(token, _mediaId);

            return(GenerateSendMessage.GenerateSendNewMessage(content, toUserName, fromUserName, dateTime));
        }