提示1003 参数不合法

解决方案 »

  1.   

    https://www.nuget.org/packages/JPush.NET/
    直接用这个dll就行了,官方的哪种不好用,大致就下面这种写法
                PushMessageRequestV3 request = new PushMessageRequestV3()
                {
                    Platform = platform,
                    AppMessage = message,
                    Audience = audience,
                    Notification = notification
                };
    Client.SendPushMessage(request)
      

  2.   

        public static class JPushHelper
        {
            private class JPushQueue
            {
                public PushMessageRequestV3 Request { get; set; }
                public LogWriter Log { get; set; }
            }
            private static readonly ConcurrentQueue<JPushQueue> Queue = new ConcurrentQueue<JPushQueue>();
            private static readonly JPushClientV3 Client;
            static JPushHelper()
            {
                bool testEnv;
                bool.TryParse(ConfigurationManager.AppSettings["JPushTestEnvironment"], out testEnv);
                Client = new JPushClientV3(ConfigurationManager.AppSettings[$"JPushAppKey"],
                    ConfigurationManager.AppSettings[$"JPushSecretKey"], testEnv);
                Task.Run(() => { Execute(); });
            }
            private static void Execute()
            {
                while (true)
                {
                    JPushQueue request;
                    if (Queue.TryPeek(out request)
                        && Execute(request))
                    {
                        while (!Queue.TryDequeue(out request))
                        {
                            //do nothing
                        }
                        continue;
                    }
                }
            }
            private static bool Execute(JPushQueue request)
            {
                try
                {
                    var response = Client.SendPushMessage(request.Request);
                    if (request.Log != null)
                    {
                        request.Log.Info(GetLogInfos(request.Request, response));
                    }
                    return response.ResponseCode == PushResponseCode.Succeed;
                }
                catch(Exception ex)
                {
                    if (request.Log != null)
                    {
                        string responseContent = string.Empty;
                        HttpOperationException webEx = ex as HttpOperationException;
                        if (webEx == null)
                        {
                            webEx = ex.InnerException as HttpOperationException;
                        }
                        if (webEx != null)
                        {
                            responseContent = webEx.ExceptionReference.ResponseText;
                        }
                        request.Log.Error($@"Exception:{ex}
    ResponseContent:{responseContent}
    推送数据:{JsonConvert.SerializeObject(request.Request)}");
                    }
                    return true;
                }
            }
            private static string GetLogInfos(PushMessageRequestV3 request, PushResponse response)
            {
                StringBuilder tmp = new StringBuilder();
                tmp.AppendLine("***********  Request  ***********");
                tmp.AppendLine(JsonConvert.SerializeObject(request));
                tmp.AppendLine("***********  Response  ***********");
                tmp.AppendLine(JsonConvert.SerializeObject(response));
                return tmp.ToString();
            }        public static void Push(PushPlatform platform, Audience audience, Notification notification, AppMessage message, LogWriter log = null)
            {
                PushMessageRequestV3 request = new PushMessageRequestV3()
                {
                    Platform = platform,
                    AppMessage = message,
                    Audience = audience,
                    Notification = notification
                };
                Queue.Enqueue(new JPushQueue
                {
                    Request = request,
                    Log = log
                });
            }
        }
    就这么简单啊,没啥实例了,这个是已经在线上运行了的
      

  3.   

    类库就是上面4L那个链接啊,你通过nuget安装就行了
    然后这个代码是简单的一个内存队列,只发一次,不管发不发成功
      

  4.   


            /// <summary>
            /// JPushV3
            /// </summary>
            /// <param name="RegistrationID"></param>
            /// <param name="type"></param>
            /// <param name="content"></param>
            /// <param name="isType"></param>
            /// <returns></returns>
            public string JPush(string RegistrationID, string type, string content,int isType)//0默认全体 1个人
            {            string app_key = string.Empty;
                string masterSecret = string.Empty;            app_key = "";
                masterSecret = "";            string postData = string.Empty;
                if (isType == 1)
                {
                    postData = "{\"platform\":\"all\",\"audience\":{\"alias\":[" + RegistrationID + "]},\"message\":{\"msg_content\":\"" + content + "\",\"extras\":{\"pushType\":\"" + type + "\"}},\"options\":{\"apns_production\":true},\"notification\":{ \"android\":{\"alert\":\"" + content + "\"},\"ios\":{\"alert\":\"" + content + "\",\"sound\":\"default\",\"badge\":\"+1\"}}}";
                }
                else
                {
                    postData = "{\"platform\":\"all\",\"audience\":\"all\",\"message\":{\"msg_content\":\"" + content + "\",\"extras\":{\"pushType\":\"" + type + "\"}},\"options\":{\"apns_production\":true},\"notification\":{ \"android\":{\"alert\":\"" + content + "\"},\"ios\":{\"alert\":\"" + content + "\",\"sound\":\"default\",\"badge\":\"+1\"}}}";
                }            byte[] data = UTF8Encoding.UTF8.GetBytes(postData);
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://api.jpush.cn/v3/push");            myRequest.Method = "POST";//极光http请求方式为post  
                myRequest.ContentType = "application/json";//按照极光的要求  
                byte[] base64 = System.Text.Encoding.Default.GetBytes(app_key + ":" + masterSecret);
                myRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(base64));
                myRequest.ContentLength = data.Length;
                //System.GC.Collect();
                //myRequest.KeepAlive = false;
                Stream newStream = myRequest.GetRequestStream();
                // Send the data.  
                newStream.Write(data, 0, data.Length);
                newStream.Close();            // Get response  
                var response = (HttpWebResponse)myRequest.GetResponse();
                using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")))
                {
                    string result = reader.ReadToEnd();
                    reader.Close();
                    response.Close();
                    //myRequest.Abort();
                    return result;
                }
            }
      

  5.   

    你好,请问,c#的winform怎么接收极光推送服务器发来的消息?
    -----------------------