コード例 #1
0
ファイル: TextMsgHandler.cs プロジェクト: liusile/WeiXinDemo
 public object Response()
 {
     var response = new TextMessageResponse
     {
         Content      = "hello",
         CreateTime   = DateTimeHelper.GetCurDateTime(),
         MsgType      = request.MsgType,
         FromUserName = request.ToUserName,
         ToUserName   = request.FromUserName
     };
 }
コード例 #2
0
        public Task <MessageResponse> Processed(TextMessageRequest request)
        {
            MessageResponse response = new TextMessageResponse
            {
                ToUserName   = request.ToUserName,
                FormUserName = request.FormUserName,
                CreateTime   = request.CreateTime,
                Content      = "回复"
            };

            return(Task.FromResult(response));
        }
コード例 #3
0
ファイル: XmlConvert.cs プロジェクト: Allen-Wei/Alan.Utils
        public static void Run()
        {
            var xml = @"<xml><ToUserName><![CDATA[gh_3209e49c0c17]]></ToUserName>
<FromUserName><![CDATA[oLntxs52aj9suPa5XxqWPKmpB4zs]]></FromUserName>
<CreateTime>1450255418</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[hello]]></Content>
<MsgId>6228799591557931974</MsgId>
</xml>";
            var model = xml.ExXmlToEntity<Model>();

            var rep = new TextMessageResponse()
            {
                Content = "hello",
                ToUserName = "******",
                CreateTime = DateTime.Now.ToShortDateString()
            };
            var repXml = model.ExToXml();
        }
コード例 #4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            BaseMessageResponse[] result = null;

            var jArray = JArray.Load(reader);

            if (jArray != null)
            {
                result = new BaseMessageResponse[jArray.Count];

                for (var i = 0; i < jArray.Count; i++)
                {
                    var messageType = (Domain.Enum.Type)System.Enum.Parse(typeof(Domain.Enum.Type), jArray[i]["type"].ToString());

                    switch (messageType)
                    {
                    case Domain.Enum.Type.Text:
                        result[i] = new TextMessageResponse();
                        break;

                    case Domain.Enum.Type.Card:
                        result[i] = new CardMessageResponse();
                        break;

                    case Domain.Enum.Type.QuickReply:
                        result[i] = new QuickReplyMessageResponse();
                        break;

                    case Domain.Enum.Type.Image:
                        result[i] = new ImageMessageResponse();
                        break;

                    default:
                        result[i] = null;
                        break;
                    }
                }
            }

            return(result);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            string[]            dest     = new string[2];
            SmsGatewayService   sms      = new SmsGatewayService();
            TextMessageRequest  request  = new TextMessageRequest();
            Credentials         cr       = new Credentials();
            TextMessage         tm       = new TextMessage();
            TextMessageResponse response = new TextMessageResponse();

// Tiempo maximo de respuesta en milisegundos
            sms.Timeout = 60000; //milisec

// XX, YY y ZZ se corresponden con los valores de identificación del usuario en el sistema
//domainId solo es necesario si el login no es un email
//cr.domainId = "XX";
            cr.login  = "******";
            cr.passwd = "ZZ";

            tm.encoding = "UTF-8";
            tm.msg      = "Mensaje de prueba";
//No es posible utilizar el remitente en América pero sí en España y Europa
//Descomentar la línea solo si se cuenta con un remitente autorizado por Altiria
//tm.senderId = "remitente";

            dest[0] = "346xxxxxxxx";
            dest[1] = "346yyyyyyyy";

            request.credentials = cr;
            request.destination = dest;
            request.message     = tm;

            try {
                response = sms.sendSms(request);

                if (response.status != "000")
                {
                    Console.WriteLine("Código de error de Altiria: " + response.status);
                }
                else
                {
                    Console.WriteLine("Código de Altiria: " + response.status);
                    foreach (TextDestination rd in response.details)
                    {
                        Console.WriteLine("  " + rd.destination + ": Código de respuesta " + rd.status);
                    }
                }
            }
            catch (WebException e) {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    Console.WriteLine("Error TimeOut");
                }
                else
                {
                    Console.WriteLine("ERROR " + e.Message);
                }
            }
            catch (Exception e) {
                Console.WriteLine("ERROR: " + e.Message);
            }
        }