Browse Source

1.增加微信登录及微信绑定。

tomatozq 5 năm trước cách đây
mục cha
commit
8c0d490b69

+ 168 - 98
picc-admin-server/src/main/java/com/jpsoft/picc/modules/business/controller/InsurancePolicyController.java

@@ -1,19 +1,27 @@
 package com.jpsoft.picc.modules.business.controller;
 
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.json.JSON;
+import cn.hutool.json.JSONObject;
 import com.github.pagehelper.Page;
+import com.jpsoft.picc.modules.base.entity.Company;
+import com.jpsoft.picc.modules.base.entity.CompanyUser;
 import com.jpsoft.picc.modules.base.entity.InsuranceAgent;
 import com.jpsoft.picc.modules.base.entity.InsuranceDefinitionLimit;
+import com.jpsoft.picc.modules.base.service.CompanyService;
+import com.jpsoft.picc.modules.base.service.CompanyUserService;
 import com.jpsoft.picc.modules.base.service.InsuranceAgentService;
 import com.jpsoft.picc.modules.base.service.InsuranceDefinitionLimitService;
 import com.jpsoft.picc.modules.business.entity.*;
 import com.jpsoft.picc.modules.business.service.*;
 import com.jpsoft.picc.modules.common.config.PdfConfig;
+import com.jpsoft.picc.modules.common.config.WeixinConfig;
 import com.jpsoft.picc.modules.common.constant.PolicyStatus;
 import com.jpsoft.picc.modules.common.dto.MessageResult;
 import com.jpsoft.picc.modules.common.dto.Sort;
 import com.jpsoft.picc.modules.common.utils.ItextPDFUtil;
 import com.jpsoft.picc.modules.common.utils.PojoUtils;
+import com.jpsoft.picc.modules.common.utils.WeixinUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -31,7 +39,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.File;
+import java.security.Policy;
 import java.util.*;
+import java.util.concurrent.Executor;
 
 @RestController
 @RequestMapping("/insurancePolicy")
@@ -60,6 +70,15 @@ public class InsurancePolicyController {
     @Autowired
     private InsuranceDefinitionLimitService insuranceDefinitionLimitService;
 
+    @Autowired
+    private CompanyService companyService;
+
+    @Autowired
+    private CompanyUserService companyUserService;
+
+    @Autowired
+    private WeixinConfig weixinConfig;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<InsurancePolicy> create(){
@@ -336,36 +355,67 @@ public class InsurancePolicyController {
             @ApiImplicitParam(name="opinion",value = "意见",required = true,paramType = "query")
     })
     public MessageResult<Integer> firstApproval(String applicationId,String policyId,String processStatus,String opinion, @RequestAttribute String subject){
-
         //当前用户ID
         System.out.println(subject);
 
         MessageResult<Integer> msgResult = new MessageResult<>();
 
-        String status ="";
+        try {
+            PolicyStatus policyStatus;
 
-        if(processStatus.equals("正常")){
-            //30
-            status = String.valueOf(PolicyStatus.PendingRetrial.getValue());
-        }
-        else{
-            //15
-            status = String.valueOf(PolicyStatus.Back.getValue());
-        }
+            if (processStatus.equals("正常")) {
+                //30
+                policyStatus = PolicyStatus.PendingRetrial;
+            } else {
+                //15
+                policyStatus = PolicyStatus.Back;
+            }
 
-        int affectCount = approval(applicationId,policyId,processStatus,opinion,status ,subject);
+            int affectCount = approval(applicationId, policyId, processStatus, opinion, policyStatus.getValue() + "", subject);
 
-        if(affectCount > 0){
-            //修改花名册人员状态为初审
-            check(policyId,"1",subject);
-        }
+            if (affectCount > 0) {
+                //修改花名册人员状态为初审
+                check(policyId, "1", subject);
+            }
 
-        msgResult.setResult(true);
-        msgResult.setData(affectCount);
+            //发送微信通知
+            sendWeixinMessage(applicationId, policyStatus);
+
+            msgResult.setResult(true);
+            msgResult.setData(affectCount);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+            msgResult.setMessage(ex.getMessage());
+        }
 
         return msgResult;
     }
 
+    private void sendWeixinMessage(String applicationId, PolicyStatus policyStatus) {
+        InsuranceApplication insuranceApplication = insuranceApplicationService.get(applicationId);
+        Company company = companyService.get(insuranceApplication.getCompanyId());
+        CompanyUser companyUser = companyUserService.findByCompanyId(company.getId());
+
+        if (companyUser!=null && StringUtils.isNotEmpty(companyUser.getOpenId())){
+            JSONObject jsonObject = new JSONObject();
+
+            JSONObject userNameObj = new JSONObject();
+            userNameObj.put("value",companyUser.getUserName());
+
+            jsonObject.put("userName",userNameObj);
+
+            JSONObject statusObj = new JSONObject();
+            statusObj.put("value",policyStatus.getText());
+
+            jsonObject.put("status",statusObj);
+
+            new Thread(()->WeixinUtil.sendTemplateMessage(weixinConfig,
+                    companyUser.getOpenId(),
+                    weixinConfig.getSendTmplId1(), jsonObject)
+            ).start();
+        }
+    }
 
     @ApiOperation(value="PICC复审")
     @RequestMapping(value = "secondApproval",method = RequestMethod.POST)
@@ -382,38 +432,48 @@ public class InsurancePolicyController {
 
         MessageResult<Integer> msgResult = new MessageResult<>();
 
-        String status ="";
-
-        if(processStatus.equals("正常")){
-            //40
-            InsurancePolicy insurancePolicy = insurancePolicyService.get(policyId);
-            if(insurancePolicy != null){
-                int no = insurancePolicy.getNo();
-                if(no > 1){
-                    //待制单
-                    status = String.valueOf(PolicyStatus.PendingMakePolicy.getValue());
-                }else{
-                    //待缴费
-                    status = String.valueOf(PolicyStatus.PendingPay.getValue());
+        try {
+            PolicyStatus policyStatus;
+
+            if (processStatus.equals("正常")) {
+                //40
+                InsurancePolicy insurancePolicy = insurancePolicyService.get(policyId);
+
+                if (insurancePolicy != null) {
+                    int no = insurancePolicy.getNo();
+                    if (no > 1) {
+                        //待制单
+                        policyStatus = PolicyStatus.PendingMakePolicy;
+                    } else {
+                        //待缴费
+                        policyStatus = PolicyStatus.PendingPay;
+                    }
+                } else {
+                    throw new Exception("下月投保单不存在");
                 }
+            } else {
+                //20
+                policyStatus = PolicyStatus.PendingTrial;
             }
 
-            //status = String.valueOf(PolicyStatus.PendingPay.getValue());
-        }
-        else{
-            //20
-            status = String.valueOf(PolicyStatus.PendingTrial.getValue());
-        }
+            int affectCount = approval(applicationId, policyId, processStatus, opinion, policyStatus.getValue() + "", subject);
 
-        int affectCount = approval(applicationId,policyId,processStatus,opinion,status ,subject);
+            if (affectCount > 0) {
+                //修改花名册人员状态为初审
+                check(policyId, "2", subject);
+            }
 
-        if(affectCount > 0){
-            //修改花名册人员状态为初审
-            check(policyId,"2",subject);
-        }
+            //发送微信通知
+            sendWeixinMessage(applicationId, policyStatus);
 
-        msgResult.setResult(true);
-        msgResult.setData(affectCount);
+            msgResult.setResult(true);
+            msgResult.setData(affectCount);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+            msgResult.setMessage(ex.getMessage());
+            msgResult.setResult(false);
+        }
 
         return msgResult;
     }
@@ -432,54 +492,55 @@ public class InsurancePolicyController {
 
         //当前用户ID
         System.out.println(subject);
-
         MessageResult<Integer> msgResult = new MessageResult<>();
 
-        String status ="";
-
-        if(processStatus.equals("正常")){
-            //70
-            status = String.valueOf(PolicyStatus.SendOutPolicy.getValue());
-        }
-        else{
-            //50
-            status = String.valueOf(PolicyStatus.PendingMakePolicy.getValue());
-        }
+        try {
+//        String status ="";
+            PolicyStatus policyStatus;
 
-        if(StringUtils.isNotEmpty(insurancePolicyFile)){
+            if (processStatus.equals("正常")) {
+                //70
+                policyStatus = PolicyStatus.SendOutPolicy;
+            } else {
+                //50
+                policyStatus = PolicyStatus.PendingMakePolicy;
+            }
 
-            InsurancePolicy insurancePolicy = insurancePolicyService.get(policyId);
+            if (StringUtils.isNotEmpty(insurancePolicyFile)) {
+                InsurancePolicy insurancePolicy = insurancePolicyService.get(policyId);
 
-            insurancePolicy.setInsurancePolicyFile(insurancePolicyFile);
+                insurancePolicy.setInsurancePolicyFile(insurancePolicyFile);
 
-            insurancePolicyService.update(insurancePolicy);
-        }
+                insurancePolicyService.update(insurancePolicy);
+            }
 
-        int affectCount = approval(applicationId,policyId,processStatus,opinion,status ,subject);
+            int affectCount = approval(applicationId, policyId, processStatus, opinion, policyStatus.getValue() + "", subject);
 
-        boolean flag = false;
-        String msg = "";
+            boolean flag = false;
+            String msg = "";
 
-        if(affectCount > 0 ){
-            if(processStatus.equals("正常")) {
-                //生成下月投保单
-                try {
+            if (affectCount > 0) {
+                if (processStatus.equals("正常")) {
+                    //生成下月投保单
                     generatePolicyInTrans(applicationId, policyId, subject);
+
+                    //发送微信通知
+                    sendWeixinMessage(applicationId, policyStatus);
+                } else {
                     flag = true;
-                } catch (Exception ex) {
-                    flag = false;
-                    msg = ex.getMessage();
                 }
             }
-            else{
-                flag = true;
-            }
-        }
 
+            msgResult.setResult(flag);
+            msgResult.setData(affectCount);
+            msgResult.setMessage(msg);
+        }
+        catch (Exception ex) {
+            logger.error(ex.getMessage(),ex);
 
-        msgResult.setResult(flag);
-        msgResult.setData(affectCount);
-        msgResult.setMessage(msg);
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
 
         return msgResult;
     }
@@ -543,35 +604,44 @@ public class InsurancePolicyController {
 
         MessageResult<Integer> msgResult = new MessageResult<>();
 
-        String status ="";
+        try {
+//        String status ="";
+            PolicyStatus policyStatus;
 
-        if(processStatus.equals("正常")){
-            //60
-            status = String.valueOf(PolicyStatus.PendingOutPolicy.getValue());
-        }
-        else{
-            //40
-            status = String.valueOf(PolicyStatus.PendingPay.getValue());
-        }
+            if (processStatus.equals("正常")) {
+                //60
+                policyStatus = PolicyStatus.PendingOutPolicy;
+            } else {
+                //40
+                policyStatus = PolicyStatus.PendingPay;
+            }
 
-        InsurancePolicy item = insurancePolicyService.get(policyId);
+            InsurancePolicy item = insurancePolicyService.get(policyId);
 
-        item.setAccountBank(accountBank);
-        item.setIssuingBank(issuingBank);
-        item.setSinglNumber(singlNumber);
-        item.setTransferTime(new Date());
-        item.setAgentId(agentId);
+            item.setAccountBank(accountBank);
+            item.setIssuingBank(issuingBank);
+            item.setSinglNumber(singlNumber);
+            item.setTransferTime(new Date());
+            item.setAgentId(agentId);
 
-        int affectCount = insurancePolicyService.update(item);
+            int affectCount = insurancePolicyService.update(item);
 
-        int affectCount1 = 0;
+            int affectCount1 = 0;
 
-        if(affectCount>0){
-            affectCount1 = approval(applicationId,policyId,processStatus,opinion,status ,subject);
-        }
+            if (affectCount > 0) {
+                affectCount1 = approval(applicationId, policyId, processStatus, opinion, policyStatus.getValue() + "", subject);
+            }
 
-        msgResult.setResult(true);
-        msgResult.setData(affectCount1);
+            //发送微信通知
+            sendWeixinMessage(applicationId, policyStatus);
+
+            msgResult.setResult(true);
+            msgResult.setData(affectCount1);
+        }
+        catch (Exception ex){
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
 
         return msgResult;
     }

+ 3 - 1
picc-admin-server/src/main/resources/application-dev.yml

@@ -19,4 +19,6 @@ weixin:
   appId: wxc0ddd6a415c535d9
   appSecret: 042fe6c9c970c1d9fe585dccfca89221
   tokenUrl: "http://localhost:8086/weixin-middleware/token"
-  createQrCodeUrl: "http://localhost:8086/weixin-middleware/qrcode/create"
+  createQrCodeUrl: "http://localhost:8086/weixin-middleware/qrcode/create"
+  sendTmplMsgUrl: "https://api.weixin.qq.com/cgi-bin/message/template/send"
+  sendTmplId1: "oc6Kh7_ZkANmsUnl2keg-X2nUKRBkAwjnGI3z1gTodo"

+ 4 - 2
picc-admin-server/src/main/resources/application-test.yml

@@ -23,5 +23,7 @@ pdf:
 weixin:
   appId: wxc0ddd6a415c535d9
   appSecret: 042fe6c9c970c1d9fe585dccfca89221
-  tokenUrl: "http://localhost:8086/weixin-middleware/token"
-  createQrCodeUrl: "http://localhost:8086/weixin-middleware/qrcode/create"
+  tokenUrl: "http://gyxm.jing-zhou.gov.cn/weixin-middleware/token"
+  createQrCodeUrl: "http://gyxm.jing-zhou.gov.cn/weixin-middleware/qrcode/create"
+  sendTmplMsgUrl: "https://api.weixin.qq.com/cgi-bin/message/template/send"
+  sendTmplId1: "oc6Kh7_ZkANmsUnl2keg-X2nUKRBkAwjnGI3z1gTodo"

+ 2 - 0
picc-common/src/main/java/com/jpsoft/picc/modules/common/config/WeixinConfig.java

@@ -12,6 +12,8 @@ public class WeixinConfig {
     private String appSecret;
     private String tokenUrl;
     private String createQrCodeUrl;
+    private String sendTmplMsgUrl;
+    private String sendTmplId1;
 
     public final static String SCAN_QRCODE_LOGIN_PREFIX = "SCAN_QRCODE_LOGIN_";
 }

+ 51 - 0
picc-common/src/main/java/com/jpsoft/picc/modules/common/utils/WeixinUtil.java

@@ -98,4 +98,55 @@ public class WeixinUtil {
 
         return qrcodeUrl;
     }
+
+    public static boolean sendTemplateMessage(WeixinConfig config,String toUserOpenId,String templateId,JSONObject data){
+        boolean result = false;
+
+        try {
+            String accessToken = getAccessToken(config);
+
+            if (StringUtils.isEmpty(accessToken)) {
+                throw new Exception("获取基础token失败!");
+            }
+
+            StringBuilder urlBuilder = new StringBuilder();
+
+            urlBuilder.append(config.getSendTmplMsgUrl())
+                    .append("?access_token=")
+                    .append(URLEncoder.encode(accessToken, "UTF-8"));
+
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("touser", toUserOpenId);
+            jsonObject.put("template_id", templateId);
+            jsonObject.put("data", data);
+
+            StringEntity entity = new StringEntity(jsonObject.toString(), "utf-8");
+
+            entity.setContentType("application/json");//发送json数据需要设置contentType
+
+            HttpPost httpPost = new HttpPost(urlBuilder.toString());
+            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+
+            httpPost.setEntity(entity);
+
+            HttpResponse res = httpClient.execute(httpPost);
+
+            if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                String content = EntityUtils.toString(res.getEntity());
+                JSONObject ret = new JSONObject(content);
+
+                if (ret.getInt("errcode") == 0) {
+                    result = true;
+                } else {
+                    log.error(content);
+                }
+            }
+        }
+        catch (Exception ex){
+            log.error(ex.getMessage(),ex);
+            result = false;
+        }
+
+        return result;
+    }
 }

+ 16 - 2
picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/CompanyController.java

@@ -1,13 +1,15 @@
 package com.jpsoft.picc.modules.auth.controller;
 
-import com.alibaba.druid.util.StringUtils;
 import com.jpsoft.picc.modules.base.entity.Company;
+import com.jpsoft.picc.modules.base.entity.CompanyUser;
 import com.jpsoft.picc.modules.base.service.CompanyService;
+import com.jpsoft.picc.modules.base.service.CompanyUserService;
 import com.jpsoft.picc.modules.common.dto.MessageResult;
 import com.jpsoft.picc.modules.common.utils.PojoUtils;
 import com.jpsoft.picc.modules.pub.dto.CompanyInfoDTO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
 import org.jasig.cas.client.authentication.AttributePrincipal;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -24,6 +26,9 @@ public class CompanyController {
     @Autowired
     private CompanyService companyService;
 
+    @Autowired
+    private CompanyUserService companyUserService;
+
     @GetMapping(value="detail")
     @ApiOperation(value = "获取企业信息")
     public MessageResult<CompanyInfoDTO> detail(HttpServletRequest request){
@@ -34,8 +39,12 @@ public class CompanyController {
 
             //todo
             AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
+            CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
+            Company company = null;
 
-            Company company = companyService.findByCreateBy(principal.getName());
+            if (companyUser!=null && StringUtils.isNotEmpty(companyUser.getCompanyId())) {
+                company = companyService.get(companyUser.getCompanyId());
+            }
 
             if(company!=null) {
                 PojoUtils.map(company, companyInfoDTO);
@@ -93,6 +102,11 @@ public class CompanyController {
                 messageResult.setData(company.getId());
             }
 
+            CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
+            companyUser.setCompanyId(company.getId());
+            companyUser.setUpdateTime(new Date());
+            companyUserService.update(companyUser);
+
             messageResult.setResult(true);
         }
         catch (Exception ex){

+ 15 - 1
picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/pub/controller/UserController.java

@@ -1,7 +1,9 @@
 package com.jpsoft.picc.modules.pub.controller;
 
 import com.jpsoft.picc.config.CasConfig;
+import com.jpsoft.picc.modules.base.entity.Company;
 import com.jpsoft.picc.modules.base.entity.CompanyUser;
+import com.jpsoft.picc.modules.base.service.CompanyService;
 import com.jpsoft.picc.modules.base.service.CompanyUserService;
 import com.jpsoft.picc.modules.common.config.WeixinConfig;
 import com.jpsoft.picc.modules.common.constant.WeixinEvent;
@@ -49,6 +51,9 @@ public class UserController {
     @Autowired
     private CompanyUserService companyUserService;
 
+    @Autowired
+    private CompanyService companyService;
+
     @Autowired
     private ValueOperations<String,Object> valueOperations;
 
@@ -264,12 +269,13 @@ public class UserController {
                     e.printStackTrace();
                 }
 
+                //将成功调用云平台登录接口的用户信息更新
                 CompanyUser companyUser = companyUserService.findByUserName(userName);
 
                 if(companyUser!=null) {
                     companyUser.setPassword(des3.encrypt(DES3.DEFAULT_KEY, password));
                     companyUser.setUpdateTime(new Date());
-                    companyUser.setUpdateBy(companyUser.getId());
+                    companyUser.setUpdateBy(userName);
 
                     companyUserService.update(companyUser);
                 }
@@ -278,9 +284,17 @@ public class UserController {
                     companyUser.setId(UUID.randomUUID().toString());
                     companyUser.setUserName(userName);
                     companyUser.setPassword(des3.encrypt(DES3.DEFAULT_KEY, password));
+
                     companyUser.setDelFlag(false);
                     companyUser.setCreateTime(new Date());
 
+                    //修复历史数据
+                    Company company = companyService.findByCreateBy(userName);
+
+                    if (company!=null){
+                        companyUser.setCompanyId(company.getId());
+                    }
+
                     companyUserService.insert(companyUser);
                 }
 

+ 3 - 1
picc-enterprise-server/src/main/resources/application-dev.yml

@@ -30,4 +30,6 @@ weixin:
   appId: wxc0ddd6a415c535d9
   appSecret: 042fe6c9c970c1d9fe585dccfca89221
   tokenUrl: "http://localhost:8086/weixin-middleware/token"
-  createQrCodeUrl: "http://localhost:8086/weixin-middleware/qrcode/create"
+  createQrCodeUrl: "http://localhost:8086/weixin-middleware/qrcode/create"
+  sendTmplMsgUrl: "https://api.weixin.qq.com/cgi-bin/message/template/send"
+  sendTmplId: "6CMGIpbgZLtqdr9xOdyEAlrCWXh8nJ260jRdktnv7vE"

+ 8 - 0
picc-enterprise-server/src/main/resources/application-remote.yml

@@ -28,6 +28,14 @@ jpcloud:
   sellerSerialNumber: '000001000020'
   platformCode: '0008'
 
+weixin:
+  appId: wxc0ddd6a415c535d9
+  appSecret: 042fe6c9c970c1d9fe585dccfca89221
+  tokenUrl: "http://gyxm.jing-zhou.gov.cn/weixin-middleware/token"
+  createQrCodeUrl: "http://gyxm.jing-zhou.gov.cn/weixin-middleware/qrcode/create"
+  sendTmplMsgUrl: "https://api.weixin.qq.com/cgi-bin/message/template/send"
+  sendTmplId: "6CMGIpbgZLtqdr9xOdyEAlrCWXh8nJ260jRdktnv7vE"
+
 springfox:
   documentation:
     swagger:

+ 8 - 0
picc-enterprise-server/src/main/resources/application-test.yml

@@ -28,6 +28,14 @@ jpcloud:
   sellerSerialNumber: '000001000020'
   platformCode: '0008'
 
+weixin:
+  appId: wxc0ddd6a415c535d9
+  appSecret: 042fe6c9c970c1d9fe585dccfca89221
+  tokenUrl: "http://gyxm.jing-zhou.gov.cn/weixin-middleware/token"
+  createQrCodeUrl: "http://gyxm.jing-zhou.gov.cn/weixin-middleware/qrcode/create"
+  sendTmplMsgUrl: "https://api.weixin.qq.com/cgi-bin/message/template/send"
+  sendTmplId: "6CMGIpbgZLtqdr9xOdyEAlrCWXh8nJ260jRdktnv7vE"
+
 springfox:
   documentation:
     swagger:

+ 2 - 2
weixin-middleware/src/main/java/com/jpsoft/weixin/callback/EventCallback.java

@@ -32,7 +32,7 @@ public class EventCallback {
 //        this.message = message;
     }
 
-    public boolean process(String fromUserName,String toUserName,String eventKey){
+    public boolean process(String openId,String eventKey){
         boolean result = false;
 
         try {
@@ -46,7 +46,7 @@ public class EventCallback {
 
             List<NameValuePair> list = new ArrayList<NameValuePair>();
             list.add(new BasicNameValuePair("eventKey", eventKey));
-            list.add(new BasicNameValuePair("openId", toUserName));
+            list.add(new BasicNameValuePair("openId", openId));
 
             UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
             httpPost.setEntity(entity);

+ 6 - 2
weixin-middleware/src/main/java/com/jpsoft/weixin/controller/WeixinController.java

@@ -151,8 +151,12 @@ public class WeixinController {
 
             //开发者在5秒内未回复任何内容
             for (EventCallback callback: callbackList) {
-                if (eventKey.startsWith(callback.getCode())){
-                    callback.process(fromUserName,toUserName,eventKey);
+                if (StringUtils.isNotEmpty(eventKey) && eventKey.startsWith(callback.getCode())){
+                    //fromUserName 接收方帐号(收到的OpenID)
+                    //toUserName 开发者微信号
+                    callback.process(fromUserName,eventKey);
+
+                    //回复消息时,将两则颠倒
                     WeixinUtil.replyTextMessage(response,toUserName,fromUserName,callback.getMessage());
 
                     processed = true;