|
@@ -1,122 +0,0 @@
|
|
|
-package com.loan.system.utils;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
-import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
-import org.codehaus.xfire.client.Client;
|
|
|
|
|
-import org.springframework.context.ApplicationContext;
|
|
|
|
|
-import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
|
|
|
-
|
|
|
|
|
-import java.security.MessageDigest;
|
|
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @author raptor
|
|
|
|
|
- * @description WeChatUtil
|
|
|
|
|
- * @date 2021/4/1 13:21
|
|
|
|
|
- */
|
|
|
|
|
-public class WeChatUtil {
|
|
|
|
|
- private static ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
- private static ApplicationContext appContext;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- *
|
|
|
|
|
- * @param person_info
|
|
|
|
|
- * 接收人信息,每个人员信息格式为:名字|学工号|部门ID|部门名称|对应微信账号,
|
|
|
|
|
- * 人与人之间用“^@^”隔开(如果数据无法提供,可以写空,但是“|”不可省略),必须
|
|
|
|
|
- * "raptor|202050235|11644008804352|杭州电子科技大学|18758159060"
|
|
|
|
|
- * @param priority 发送优先级(1:紧急通知;2:验证码;3:立即发送;4:发送),必须
|
|
|
|
|
- * @param wechat_info 内容,必须
|
|
|
|
|
- * @return {"result":true,"msg_id":"22961055561793536","msg":"发布成功"}
|
|
|
|
|
- */
|
|
|
|
|
- public static Object sendWeChatMessage(String person_info, String priority, String wechat_info){
|
|
|
|
|
- Map<String, Object> map = new HashMap<String, Object>(16);
|
|
|
|
|
- try {
|
|
|
|
|
- appContext = new ClassPathXmlApplicationContext(new String[] {});
|
|
|
|
|
- // webservice 地址由生产环境决定
|
|
|
|
|
- org.springframework.core.io.Resource resource = appContext
|
|
|
|
|
- .getResource("http://i.hdu.edu.cn/tp_mp/service/WechatService?wsdl");
|
|
|
|
|
-
|
|
|
|
|
- /** start 协议参数 start **/
|
|
|
|
|
- // 调用接口的第三方系统协议名称。由双方协议确定。(*必填项)
|
|
|
|
|
- map.put("tp_name", "Document");
|
|
|
|
|
- // 提供接口服务的系统名称(sys/up/mp…)。由统一门户系统提供。(*必填项)
|
|
|
|
|
- map.put("sys_id", "mp");
|
|
|
|
|
- // 接口方法所属模块。由统一门户系统提供。(*必填项)
|
|
|
|
|
- map.put("module_id", "wechat");
|
|
|
|
|
- // SHA 加密后第三方系统的权限密钥值。权限密钥由统一门户系统提供。(*必填项)
|
|
|
|
|
- map.put("secret_key", getSHA("xWpDa+fGlqkXGUZLNjawGT+9MHw="));
|
|
|
|
|
- // 对应的接口方法名称,由统一门户系统提供。(*必填项)
|
|
|
|
|
- map.put("interface_method", "saveWechatInfo");
|
|
|
|
|
- /** end 协议参数 end **/
|
|
|
|
|
-
|
|
|
|
|
- map.put("person_info", person_info);
|
|
|
|
|
-
|
|
|
|
|
- map.put("send_priority", priority);
|
|
|
|
|
-
|
|
|
|
|
- /** start 业务参数 start **/
|
|
|
|
|
- //发送微信发布类型(text:⽂本;news:图⽂;image:图⽚;file:⽂件;video:视频;voice:⾳频),不可为空,参数不可省略
|
|
|
|
|
- map.put("wechat_type", "text");
|
|
|
|
|
- //内容,必须
|
|
|
|
|
- map.put("wechat_info", wechat_info);
|
|
|
|
|
- //发送⼈ID_NUMBER,需要发送回执的时候不可为空,参数不可省略
|
|
|
|
|
- map.put("operator_id_number", "09901");
|
|
|
|
|
- //发送微信附件(包括图⽚,⽂件,视频和⾳频的附件路径),为空,参数不可 省略
|
|
|
|
|
- map.put("wechat_attachment", "");
|
|
|
|
|
- //发送附件名称,为空,参数不可省略
|
|
|
|
|
- map.put("attachment_name", "");
|
|
|
|
|
- //发送附件标题,为空,参数不可省略
|
|
|
|
|
- map.put("attachment_title", "");
|
|
|
|
|
- //发送附件描述,为空,参数不可省略
|
|
|
|
|
- map.put("attachment_des", "");
|
|
|
|
|
- //发送附件时⻓(视频和⾳频),为空,参数不可省略
|
|
|
|
|
- map.put("attachment_time", "");
|
|
|
|
|
- //发送模板选择,不发送模板值为”0”,参数不可省略
|
|
|
|
|
- map.put("templet_id", "0");
|
|
|
|
|
- //发送回执选择,不发送回执值为”0”,参数不可省略
|
|
|
|
|
- map.put("receipt_id", "0");
|
|
|
|
|
- //发送⼈签名,根据模板⽽定,选择的模板有“发送⼈签名”标签的需要写值,其他为空,参数不可省略
|
|
|
|
|
- map.put("person_send", "公管处");
|
|
|
|
|
- /** end 业务参数 end **/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- String json = mapper.writeValueAsString(map);
|
|
|
|
|
- // 请求参数
|
|
|
|
|
- System.out.println("json:" + json);
|
|
|
|
|
-
|
|
|
|
|
- Client client = new Client(resource.getInputStream(), null);
|
|
|
|
|
- Object[] result = client.invoke("saveWechatInfo", new Object[] { json });
|
|
|
|
|
-
|
|
|
|
|
- // 返回结果
|
|
|
|
|
- System.out.println(result[0]);
|
|
|
|
|
-
|
|
|
|
|
- client.close();
|
|
|
|
|
- return result[0];
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取 SHA 值
|
|
|
|
|
- *
|
|
|
|
|
- * @author neusoft
|
|
|
|
|
- * @since V7.0
|
|
|
|
|
- * @param password
|
|
|
|
|
- * @return SHA(password)
|
|
|
|
|
- */
|
|
|
|
|
- private static String getSHA(String password) {
|
|
|
|
|
- try {
|
|
|
|
|
- MessageDigest sha = MessageDigest.getInstance("SHA");
|
|
|
|
|
- sha.update(password.getBytes());
|
|
|
|
|
- byte[] hash = sha.digest();
|
|
|
|
|
- return new String(Base64.encodeBase64(hash));
|
|
|
|
|
- } catch (NoSuchAlgorithmException e1) {
|
|
|
|
|
- e1.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return "";
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|