`
wangfeiaini
  • 浏览: 53331 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

极光推送服务端搭建

阅读更多
static int a = 1000;
final static String URL = "http://api.jpush.cn:8800/v2/push";//极光推送url
final static String APP_KEY = "b1bb2f134c75b20c0566d953";//极光推送申请的appkey
final static String MASTER_SRCRET = "dfa841a7caa7b43ef68de578";//md5验证key
 
/**
* 
* @param receiverType
* @param alias //在手机端设置的别名
* @param receiverValue
* @param msgType
* @param msgContent
*/
public static void pushMessage(String receiverType,String alias,String receiverValue,String msgType,
String msgContent){
       HttpPost httpRequest = new HttpPost(URL);
       a++;
       List<NameValuePair> params = new ArrayList<NameValuePair>();
       params.add(new BasicNameValuePair("sendno", a + ""));
       params.add(new BasicNameValuePair("app_key", APP_KEY));
       params.add(new BasicNameValuePair("receiver_type", receiverType));
       params.add(new BasicNameValuePair("alias", alias));
       params.add(new BasicNameValuePair("receiver_value", receiverValue));
       params.add(new BasicNameValuePair("msg_type", msgType));
       int sendno = a;
      // int receiverType = 3;
       //String receiverValue = "wang";
     //  String masterSecret = "dfa841a7caa7b43ef68de578"; 
                                                         
 
       String input = String.valueOf(sendno) + receiverType + receiverValue + MASTER_SRCRET;
       MD5 md5 = new MD5();
       String verificationCode = md5.getMD5ofStr(input);
       System.out.println("verification_code:" + verificationCode);
       params.add(new BasicNameValuePair("verification_code", verificationCode));
       
       params.add(new BasicNameValuePair("msg_type", msgType));// String.valueOf(msg_tpye)));
       JSONObject jsonObject = new JSONObject();
 
       if (Integer.valueOf(msgType) == 1)
       {
           jsonObject.put("n_content",msgContent);
       }
       else
       {
           jsonObject.put("message", msgContent);
       }
       System.err.println("jsonObject" + jsonObject.toString());
       params.add(new BasicNameValuePair("msg_content", jsonObject.toString()));
      // params.add(new BasicNameValuePair("send_description", "ren cai a "));
       params.add(new BasicNameValuePair("platform", "android"));
       params.add(new BasicNameValuePair("time_to_live", "0"));
 
       try
       {
           httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
           HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
           if (httpResponse.getStatusLine().getStatusCode() == 200)
           {
               String strResult = EntityUtils.toString(httpResponse.getEntity());
               System.out.println("get Date :" + strResult);
               return;
           }
 
       } catch (Exception e)
       {
           e.printStackTrace();
       }
   }
 

 

分享到:
评论
1 楼 wahahachuang8 2017-09-26  
GoEasy 实时推送支持IE6-IE11及大多数主流浏览器的推送,我们项目用的就是GoEasy推送,他们提供的OTP (one-time-password)能有效杜绝他人通过在页面上获取 appkey的方式,进行非法操作,十分安全!此外GoEasy目前除了在中国有服务器外还在美国,新加坡也开了服务器来支持外海推送的需求,据他们客服说接下来还会有更多的机房在世界各地……如果有全球推送需求的项目可以考虑它。

相关推荐

Global site tag (gtag.js) - Google Analytics