dcs 6 meses atrás
pai
commit
f93a8cd362

+ 2 - 2
virgo.core/src/main/java/com/bosshand/virgo/core/service/MgrUserService.java

@@ -71,7 +71,7 @@ public class MgrUserService {
 		String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + wxToken();
 		JSONObject json = new JSONObject();
 		json.put("code", code);
-		String str = WeChatUtil.httpPost(url, json);
+		String str = WeChatUtil.httpPost(url, json, null);
 		log.info("phoneNumber=" + str);
 		JSONObject jsonObject = JSONObject.parseObject(str);
 		String phoneNumber = jsonObject.getJSONObject("phone_info").getString("phoneNumber");
@@ -99,7 +99,7 @@ public class MgrUserService {
 		js.put("userId", userId);
 		js.put("nickname", name);
 		js.put("avatarUrl", CodeCache.DefaultPortrait);
-		String str = WeChatUtil.httpPost(url, js);
+		String str = WeChatUtil.httpPost(url, js, null);
 		log.info("addChatUser=" + str);
 		return str;
 	}

+ 4 - 1
virgo.core/src/main/java/com/bosshand/virgo/core/utils/WeChatUtil.java

@@ -50,7 +50,7 @@ public class WeChatUtil {
      * @param json 请求参数,请求参数应该是 json 的形式。
      * @return 所代表远程资源的响应结果
      */
-    public static String httpPost(String url, JSONObject json) {
+    public static String httpPost(String url, JSONObject json, String token) {
         PrintWriter out = null;
         BufferedReader in = null;
         String result = "";
@@ -59,6 +59,9 @@ public class WeChatUtil {
             // 打开和URL之间的连接
             URLConnection conn = realUrl.openConnection();
             // 设置通用的请求属性
+            if(token != null){
+                conn.setRequestProperty("Token", token);
+            }
             conn.setRequestProperty("accept", "*/*");
             conn.setRequestProperty("connection", "Keep-Alive");
             conn.setRequestProperty("Content-Type", "application/json");

+ 25 - 3
virgo.manager/src/main/java/com/bosshand/virgo/service/UserService.java

@@ -10,6 +10,7 @@ import com.bosshand.virgo.core.model.MgrUser;
 import com.bosshand.virgo.core.model.MgrUserRole;
 import com.bosshand.virgo.core.utils.CodeCache;
 import com.bosshand.virgo.core.utils.WeChatUtil;
+import com.bosshand.virgo.util.MD5Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -41,7 +42,28 @@ public class UserService {
     }
 
     public int update(MgrUser user) {
-        return mgrUserDao.update(user);
+        int update = mgrUserDao.update(user);
+        //修改聊天用户信息
+        JSONObject js = new JSONObject();
+        js.put("nickname", user.getName());
+        js.put("avatarUrl", user.getPortrait());
+        WeChatUtil.httpPost("http://git.waywish.com:9120/user/update", js, this.getYelToken(String.valueOf(user.getId())));
+        return update;
+    }
+
+    /**
+     * 获取Yel-Token
+     */
+    public String getYelToken(String userId) {
+        JSONObject js = new JSONObject();
+        js.put("userId", userId);
+        long timestamp = System.currentTimeMillis() + 30 * 1000;
+        js.put("timestamp", timestamp);
+        String sign = MD5Utils.code(userId + timestamp + "50abd47112ebe8c5a73f4694c96a49ce");
+        js.put("sign", sign);
+        String str = WeChatUtil.httpPost("http://git.waywish.com:9120/user/token/get", js, null);
+        JSONObject jsonObject = JSONObject.parseObject(str);
+        return jsonObject.getJSONObject("data").getString("token");
     }
 
     public void updateResources(MgrUserRole userRole) {
@@ -99,8 +121,8 @@ public class UserService {
             JSONObject js = new JSONObject();
             js.put("userId", userId);
             js.put("nickname", user.getName());
-            js.put("avatarUrl", "https://api.multiavatar.com/Starcrasher.png");
-            WeChatUtil.httpPost("http://git.waywish.com:9120/user/register", js);
+            js.put("avatarUrl", CodeCache.DefaultPortrait);
+            WeChatUtil.httpPost("http://git.waywish.com:9120/user/register", js, null);
         }
         MgrUserRole mur = mgrUserRoleDao.getUser(userId, organizationId);
         if (mur != null) {

+ 33 - 0
virgo.manager/src/main/java/com/bosshand/virgo/util/MD5Utils.java

@@ -0,0 +1,33 @@
+package com.bosshand.virgo.util;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class MD5Utils {
+    public static String code(String str) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            md.update(str.getBytes());
+            byte[] byteDigest = md.digest();
+            int i;
+            StringBuffer buf = new StringBuffer("");
+            for (int offset = 0; offset < byteDigest.length; offset++) {
+                i = byteDigest[offset];
+                if (i < 0) {
+                    i += 256;
+                }
+                if (i < 16) {
+                    buf.append("0");
+                }
+                buf.append(Integer.toHexString(i));
+            }
+            //32位加密
+            return buf.toString();
+            //16位的加密
+            //return buf.toString().substring(8, 24);
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+}