hz-zhhq-app-service/greenH5modul/.svn/pristine/59/599095a1e2b076a34209828f51c...

279 lines
9.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.jysoft;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import net.sf.json.JSONObject;
public class PushInfo_RestAPI {
/**
* 【优先使用】
* 10030环境 信息外网\互联网 调用
* 浏览器调用:
* https://mam1.ft-power.com.cn:10030/bg_task/rest/loadAppToken.do?jsonData={appcode:SYS,umsecret:123456}
*/
public static final String getTokenUrl = "https://mam.zeus2.top:10030/bg_task/rest/loadAppToken.do";
public static final String sendMessageUrl = "https://mam.zeus2.top:10030/bg_task/rest/sendMessage.do";
// public static final String getTokenUrl = "https://mam.sgcc.com.cn/bg_task/rest/loadAppToken.do";
// public static final String sendMessageUrl = "https://mam.sgcc.com.cn/bg_task/rest/sendMessage.do";
public static void main(String[] args) {
Calendar Cld = Calendar.getInstance();
int YY = Cld.get(Calendar.YEAR) ;
int MM = Cld.get(Calendar.MONTH)+1;
int DD = Cld.get(Calendar.DATE);
int HH = Cld.get(Calendar.HOUR_OF_DAY);
int mm = Cld.get(Calendar.MINUTE);
int SS = Cld.get(Calendar.SECOND);
int MI = Cld.get(Calendar.MILLISECOND);
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
/************************************************************
* **********************************************************
* **********************************************************
* 1、调用下面 getToken("SGCCINTSYS","123456"); 方法,修改应用编码、应用密码
* 2、run 运行
* 3、获取 token
* 4、注释 getToken("SGCCINTSYS","123456"); 方法
* 5、调用下面 sendMessage("SGCCINTSYS","630716928956457E992AE709B62B12F9",senddate,"1","igwsgcc00,igwsgcc01,igwsgcc02,igwsgcc441");
* 6、修改应用编码、填入获取的秘钥、修改用户
*
* 6.1、 【安装 i国网、安装应用编码对应的应用】
*
* 7、run 运行
* **********************************************************
* **********************************************************
* **********************************************************
* **********************************************************
*/
/**
* 1、获取token获取后 必须 注销此方法
* token有效期为24小时请勿重复获取。
* umsecret 密码默认:【 seuUwLBxGfg 或 123456 】
* 传入 应用编码、消息秘钥 获取token
*/
/**
* 1、安装 i国网 下载 【实验室Cordova】 应用
* 2、应用编码 SGCCINTSYS 密码默认:【 seuUwLBxGfg 或 123456 】
*/
// 【i国网】
// getToken("SGITGINTZYGW","R65G708e5I4");//国网党建
// getToken("SGCCINTGWSL","R65G708e5I4");
// getToken("SGCCINTSYS","seuUwLBxGfg");
// getToken("CQEXTEZHGY","R65G708e5I4");
// getToken("SGCCINTYDPTSYS","R65G708e5I4");
/**
* 1、安装一点通 使用手机号登录 并下载【实验室CordovaNEW】 应用
* 2、应用编码 JSEXTSYS2 密码默认:【 seuUwLBxGfg 或 123456 】
*/
// 【一点通】
// getToken("JSEXTSYS2","seuUwLBxGfg");
for(int i =0;i<1;i++)
{
String senddate =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date());
/**
* 参数说明:
* 1、appcode
* 2、token
* 3、消息标题、抬头
* 4、用户标识 1、i国网 内部 2、一点通 外部
* 5、接收用户标识 门户igwsgcc00
* 一点通18000000000
*/
/**
* 1、i国网 实验室Cordova 应用 对应用户igwsgcc00,igwsgcc01,igwsgcc02
*
*
* 2、应用编码 SGCCINTSYS
*/
// sendMessage("SGCCINTGWSL","BC4DE7597EF24E0AB4D5A63FDD794AB3",senddate,"1","ydpt_yf,wuxinzhong,wangchao1_ydpt");
// sendMessage("SGITGINTZYGW","54B63FB4BFB7444088FB7472B3239027",senddate,"1","ydpt_yf,wuxinzhong,wangchao1_ydpt,yangsf,zhulj6");
sendMessage("SGCCINTSYS","E7858AAB0B3D4F2989C8FDB8948E22B9",senddate,"1","jy_10");
// sendMessage("YDZY","4F50F8A4CB60451B9A1D9721163BB779",senddate,"1","igwsgcc300,igwjs30,igwjs21,igwsgcc299,igwsgcc16");
// sendMessage("WWYDBGSGCC","FCB23D131A56491E97B46BC99D044631",senddate,"1","ydpt_yf,ydpt_wd");
// sendMessage("SGCCINTYDPTSYS","ECBC637EF6224BCAAAFDEDB162385580",senddate,"1","ydpt_yf,ydpt_wd,chenl80");
/**
* 1、一点通 实验室 应用 对应用户18000000000,18000000002,18000000003
* 2、应用编码 JSEXTSYS2
*/
// sendMessage("JSEXTSYS2","9A6894FC1CE6455AABB643E7147AB8DD","备注标识","2","18000000000,18000000002,18000000003");
// sendMessage("CQEXTEZHGY","28322CD112B845BE97D9C399BD088E96","备注标识","2","18112935820");
}
}
public static void getToken(String appcode,String umsecret) {
try {
// 创建连接
URL url = new URL(getTokenUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=utf-8");
connection.connect();
// POST请求
DataOutputStream out = new DataOutputStream(connection
.getOutputStream());
// JSONObject obj = new JSONObject();
// // 应用编码
// obj.element("appcode",appcode);
// // 应用消息推送密码
// obj.element("umsecret", umsecret);
String objJson = "{appcode:"+appcode+",umsecret:"+umsecret+"}";
out.writeBytes("jsonData=" +objJson);
out.flush();
out.close();
// 读取响应
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String lines;
StringBuffer sb = new StringBuffer("");
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sb.append(lines);
}
System.out.println("获取json " + sb);
// parameter="{\"success\":true,\"message\":\"获取token值成功!\",\"data\":{\"token\":\"AFDD7615A9D544C1AB034D9E08FB2F83\",\"appcode\":\"LDXYC\"}}";
String parameter = sb.toString();
JSONObject jsonObject = JSONObject.fromObject(parameter);
System.out.println("success: " + jsonObject.get("success"));
System.out.println("message: " + jsonObject.get("message"));
System.out.println("token: "
+ jsonObject.getJSONObject("data").get("token"));
String token = jsonObject.getJSONObject("data").get("token")
.toString();
// sendMessage(token);
reader.close();
// 断开连接
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void sendMessage(String appcode,String token,String tm,String usertype,String users) {
try {
// 创建连接
URL url = new URL(sendMessageUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=utf-8");
connection.connect();
// POST请求
DataOutputStream out = new DataOutputStream(connection
.getOutputStream());
// JSONObject obj = new JSONObject();
//
// obj.element("msgname", "消息标题"+tm);
//// obj.element("subtitle", "消息抬头"+tm);
// obj.element("subtitle", "");
Map<String,String> map = new HashMap<String,String>();
map.put("msgname", "消息标题"+tm);
map.put("subtitle", "消息抬头");
// obj.element("suburl", "/view/pushInfo.html?token=aaa&info=8"); // cordova
// obj.element("suburl", "/index.html"); // cordova
/**
* hybrid/html/index.html 资源路径
* ? 分隔符
* token=aaa&info=8 参数 1 & 参数 2
* _bids=SGCCINTGWSL 应用编码 _bids=SGCCINTGWSL
*/
// obj.element("suburl", "hybrid/html/index.html?token=aaa&info=8&_bids=SGCCINTSYS");// 新开发平台
map.put("suburl", "hybrid/html/index.html?token=aaa&info=8&_bids=SGCCINTSYS");
// obj.element("suburl", "");// 新开发平台
map.put("content", "消息内容"+tm);
map.put("type", "2");
map.put("msgflag", "1");
map.put("pushtype", "2");
map.put("appcode", appcode);
map.put("token", token);
map.put("version", "null");
map.put("address", "www.baidu.com");
map.put("usertype", usertype);
map.put("useridetype", "1");
map.put("extend3", "3");
map.put("priority", "1");
map.put("users", users);
//节点标示 此处默认 10 无需修改
map.put("procode", "10");
String mapJson = JSON.toJSONString(map);
out.writeBytes("jsonData=" + URLEncoder.encode(mapJson, "utf-8"));
out.flush();
out.close();
// 读取响应
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String lines;
StringBuffer sb = new StringBuffer("");
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "UTF-8");
sb.append(lines);
}
System.out.println("获取json " + sb);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}