zh 3 жил өмнө
parent
commit
c7b051efbd

+ 5 - 6
boman-auth/src/main/java/com/boman/auth/controller/TokenController.java

@@ -17,6 +17,8 @@ import com.boman.common.core.utils.StringUtils;
 import com.boman.common.security.service.TokenService;
 import com.boman.system.api.model.LoginUser;
 
+import java.util.Map;
+
 /**
  * token 控制
  *
@@ -37,7 +39,6 @@ public class TokenController {
 
     @PostMapping("login")
     public R<?> login(@RequestBody LoginBody form) {
-        String unionId = "";
         String openId = "";
         // 验证是pc还是小程序
         if (form.getLogintype() != null && form.getLogintype().equals(WechatEnum.W.getValue())) {
@@ -45,11 +46,10 @@ public class TokenController {
             if ((Integer) result.get(AjaxResult.CODE_TAG) != 0) {
                 throw new BaseException((String) result.get(AjaxResult.MSG_TAG));
             }
-            JSONObject jsonObject = (JSONObject) result.get(AjaxResult.DATA_TAG);
+            Map<String, Object> jsonObject = (Map<String, Object>) result.get(AjaxResult.DATA_TAG);
             if (jsonObject == null) {
                 throw new BaseException("未获取到微信鉴权相关信息!");
             }
-            unionId = (String) jsonObject.get("unionid");
             openId = (String) jsonObject.get("openId");
         }
         // 用户登录
@@ -57,10 +57,9 @@ public class TokenController {
         // 如果是微信登录并且获取到的用户的unionId不为空
         if (form.getLogintype() != null
                 && form.getLogintype().equals(WechatEnum.W.getValue())
-                && StringUtils.isNotEmpty(unionId)) {
+                && StringUtils.isNotEmpty(openId)) {
             SysUser sysUser = new SysUser();
-            sysUser.setId(userInfo.getUserid());
-            sysUser.setUnionId(unionId);
+            sysUser.setId(userInfo.getSysUser().getId());
             sysUser.setOpenId(openId);
             AjaxResult updateResult = sysLoginService.updateUnionId(sysUser);
             if((Integer) updateResult.get(AjaxResult.CODE_TAG) != 0) {

+ 1 - 1
boman-modules/boman-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -144,7 +144,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</insert>
 
 	<update id="updateUnionId" parameterType="com.boman.domain.SysUser">
-		update sys_user set union_id = #{unionId},open_id = #{openId} where id = #{id}
+		update sys_user set open_id = #{openId} where id = #{id}
 	</update>
 
 	

+ 1 - 1
boman-web-core/src/main/java/com/boman/web/core/mapper/MessageMapper.java

@@ -95,7 +95,7 @@ public interface MessageMapper {
         }
 
         public String selectByCondition(Map<String, Object> para) {
-            String result = "SELECT t.message_title, t.message_code, t.send_user_id, t.send_user_name, t.create_dept_name, r.receive_time, t.id, "
+            String result = "SELECT t.message_title, t.message_code, t.send_user_id, t.send_user_name, t.create_dept_name, r.send_time as receive_time, t.id,r.from_dept_name, "
                     + " t.finish_time, r.id as receive_id FROM boman_message t JOIN urge_read_message u ON u.message_id = t.id  AND u.receive_user_name = '" + para.get("username") + "' "
                     + " JOIN boman_message_receive r on r.receive_user_name = u.receive_user_name and r.message_id = t.id "
                     + " WHERE t.is_del = 'N'  and r.`status` = 'N' ORDER BY t.create_time DESC  LIMIT " + para.get("limit") + "," + para.get("offset");

+ 7 - 4
boman-wechat/src/main/java/com/boman/wechat/controller/WechatInfoController.java

@@ -5,10 +5,7 @@ import com.boman.domain.form.LoginBody;
 import com.boman.wechat.service.WechatService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * 微信登录验证
@@ -27,4 +24,10 @@ public class WechatInfoController {
     public AjaxResult getWechatInfo(@RequestBody LoginBody loginBody) {
         return wechatService.getWechatInfo(loginBody);
     }
+
+    @ApiOperation(value = "小程序模板id获取")
+    @GetMapping("/tmpIds")
+    public AjaxResult getTmpIds() {
+        return wechatService.getTmpIds();
+    }
 }

+ 6 - 0
boman-wechat/src/main/java/com/boman/wechat/service/WechatService.java

@@ -11,4 +11,10 @@ import com.boman.domain.form.LoginBody;
 public interface WechatService {
 
     AjaxResult getWechatInfo(LoginBody loginBody);
+
+    /**
+     * 获取模板id集合
+     * @return
+     */
+    AjaxResult getTmpIds();
 }

+ 15 - 1
boman-wechat/src/main/java/com/boman/wechat/service/impl/WechatServiceImpl.java

@@ -53,6 +53,7 @@ public class WechatServiceImpl implements WechatService {
         if(authInfo == null) {
             return AjaxResult.error(-1, "未获取到认证");
         }
+        logger.info("微信返回的数据:" + authInfo.toJSONString());
         String errMsg = this.validatWechatInfo(authInfo);
         if(StringUtils.isNotEmpty(errMsg)) {
             return AjaxResult.error(-1, errMsg);
@@ -70,9 +71,17 @@ public class WechatServiceImpl implements WechatService {
         infoJsonObject.put("unionid", authInfo.get("unionid"));
         infoJsonObject.put("openId", openId);
         infoJsonObject.put("sessionKey", sessionKey);
+        logger.info("微信登陆验证返回的数据: " + infoJsonObject.toJSONString());
         return AjaxResult.successZero(infoJsonObject);
     }
 
+    @Override
+    public AjaxResult getTmpIds() {
+        String str = properties.getTemplateId();
+        String[] ids = str.split(",");
+        return AjaxResult.success(ids);
+    }
+
     /**
      * 解析返回的状态码对应的问题
      *
@@ -81,7 +90,10 @@ public class WechatServiceImpl implements WechatService {
      */
     private String validatWechatInfo(JSONObject authInfo) {
         String errMsg = "";
-        int errcode =  (Integer) authInfo.get("errcode");
+        Integer errcode =  (Integer) authInfo.get("errcode");
+        if(errcode == null) {
+            return errMsg;
+        }
         switch (errcode) {
             case -1:
                 errMsg = "系统繁忙,此时请开发者稍候再试";
@@ -94,6 +106,8 @@ public class WechatServiceImpl implements WechatService {
                 break;
             case 45011:
                 errMsg = "频率限制,每个用户每分钟100次";
+            case 40163:
+                errMsg = "code已经被使用";
                 break;
             default:
                 errMsg = (String) authInfo.get("errmsg");

+ 1 - 1
boman-wechat/src/main/java/com/boman/wechat/service/impl/WxPushServiceImpl.java

@@ -81,7 +81,7 @@ public class WxPushServiceImpl implements WxPushService {
             logger.info("result {}", responseEntity.getBody());
         }
         if(responseResult.size() > 0) {
-            pushResult.put("msg", "有用户推送失败!");
+            pushResult.put("msg", responseResult.toString());
             pushResult.put("data", responseResult);
         }
         return pushResult;