|
|
@@ -2,6 +2,7 @@ package com.iformall.controller; |
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult; |
|
|
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult; |
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
@@ -246,63 +247,69 @@ public class WxWeappInfoController extends BaseController { |
|
|
|
|
|
|
|
|
// 设置微信模板 |
|
|
// 设置微信模板 |
|
|
if(weappBasicSet.getType().equals(EnumAppType.C.getCode())) { |
|
|
if(weappBasicSet.getType().equals(EnumAppType.C.getCode())) { |
|
|
WxAppinfo appinfo = appinfoService.getByAppId(appId); |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
if(authorizerInfo.getTemplateStatus() == null || |
|
|
|
|
|
!authorizerInfo.getTemplateStatus().equals(EnumWxAuthotizationTemplateStatus.SUCCESS.getCode())) { |
|
|
|
|
|
// 模板未设置或者设置失败 |
|
|
|
|
|
// 获取模板 |
|
|
|
|
|
WxAppinfo appinfo = appinfoService.getByAppId(appId); |
|
|
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); |
|
|
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); |
|
|
// 核销成功消息 |
|
|
|
|
|
JSONObject verify_success = templeObj.getJSONObject("verify_success"); |
|
|
|
|
|
JSONArray keyidlist = verify_success.getJSONArray("keyword_id_list"); |
|
|
|
|
|
List<Integer> keyArr = getIdList(keyidlist); |
|
|
|
|
|
WxMaTemplateAddResult ret = maService.getTemplateService().addTemplate(verify_success.getString("id"), keyArr); |
|
|
|
|
|
logger.info(ret.toString()); |
|
|
|
|
|
if(appinfo != null) { |
|
|
|
|
|
// wx_template_msg |
|
|
|
|
|
WxTemplateMsg templateMsgQ = new WxTemplateMsg(); |
|
|
|
|
|
templateMsgQ.setTenantId(appinfo.getTenantId()); |
|
|
|
|
|
templateMsgQ.setType(EnumTemplateType.VERIFY_SUCCESS.getCode()); |
|
|
|
|
|
WxTemplateMsg templateMsg = templateMsgService.getByObj(templateMsgQ); |
|
|
|
|
|
if(templateMsg != null) { |
|
|
|
|
|
templateMsg.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsg); |
|
|
|
|
|
} else { |
|
|
|
|
|
templateMsgQ.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsgQ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 核销成功消息 |
|
|
|
|
|
JSONObject verify_success = templeObj.getJSONObject("verify_success"); |
|
|
|
|
|
JSONArray keyidlist = verify_success.getJSONArray("keyword_id_list"); |
|
|
|
|
|
List<Integer> keyArr = getIdList(keyidlist); |
|
|
|
|
|
WxMaTemplateAddResult ret = maService.getTemplateService().addTemplate(verify_success.getString("id"), keyArr); |
|
|
|
|
|
logger.info(ret.toString()); |
|
|
|
|
|
if(appinfo != null) { |
|
|
|
|
|
// wx_template_msg |
|
|
|
|
|
WxTemplateMsg templateMsgQ = new WxTemplateMsg(); |
|
|
|
|
|
templateMsgQ.setTenantId(appinfo.getTenantId()); |
|
|
|
|
|
templateMsgQ.setType(EnumTemplateType.VERIFY_SUCCESS.getCode()); |
|
|
|
|
|
WxTemplateMsg templateMsg = templateMsgService.getByObj(templateMsgQ); |
|
|
|
|
|
if(templateMsg != null) { |
|
|
|
|
|
templateMsg.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsg); |
|
|
|
|
|
} else { |
|
|
|
|
|
templateMsgQ.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsgQ); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// 核销失败消息 |
|
|
|
|
|
JSONObject verify_fail = templeObj.getJSONObject("verify_fail"); |
|
|
|
|
|
keyidlist = verify_fail.getJSONArray("keyword_id_list"); |
|
|
|
|
|
List<Integer> keyArr1 = getIdList(keyidlist); |
|
|
|
|
|
ret = maService.getTemplateService().addTemplate(verify_fail.getString("id"), keyArr1); |
|
|
|
|
|
logger.info(ret.toString()); |
|
|
|
|
|
if(appinfo != null) { |
|
|
|
|
|
// wx_template_msg |
|
|
|
|
|
WxTemplateMsg templateMsgQ = new WxTemplateMsg(); |
|
|
|
|
|
templateMsgQ.setTenantId(appinfo.getTenantId()); |
|
|
|
|
|
templateMsgQ.setType(EnumTemplateType.VERIFY_FAIL.getCode()); |
|
|
|
|
|
WxTemplateMsg templateMsg = templateMsgService.getByObj(templateMsgQ); |
|
|
|
|
|
if(templateMsg != null) { |
|
|
|
|
|
templateMsg.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsg); |
|
|
|
|
|
} else { |
|
|
|
|
|
templateMsgQ.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsgQ); |
|
|
|
|
|
|
|
|
// 核销失败消息 |
|
|
|
|
|
JSONObject verify_fail = templeObj.getJSONObject("verify_fail"); |
|
|
|
|
|
keyidlist = verify_fail.getJSONArray("keyword_id_list"); |
|
|
|
|
|
List<Integer> keyArr1 = getIdList(keyidlist); |
|
|
|
|
|
ret = maService.getTemplateService().addTemplate(verify_fail.getString("id"), keyArr1); |
|
|
|
|
|
logger.info(ret.toString()); |
|
|
|
|
|
if(appinfo != null) { |
|
|
|
|
|
// wx_template_msg |
|
|
|
|
|
WxTemplateMsg templateMsgQ = new WxTemplateMsg(); |
|
|
|
|
|
templateMsgQ.setTenantId(appinfo.getTenantId()); |
|
|
|
|
|
templateMsgQ.setType(EnumTemplateType.VERIFY_FAIL.getCode()); |
|
|
|
|
|
WxTemplateMsg templateMsg = templateMsgService.getByObj(templateMsgQ); |
|
|
|
|
|
if(templateMsg != null) { |
|
|
|
|
|
templateMsg.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsg); |
|
|
|
|
|
} else { |
|
|
|
|
|
templateMsgQ.setTemplateId(ret.getTemplateId()); |
|
|
|
|
|
templateMsgService.saveOrUpdate(templateMsgQ); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 更新状态 |
|
|
|
|
|
authorizerInfo.setTemplateStatus(0); |
|
|
|
|
|
authorizerInfo.setTemplateTime(new Date()); |
|
|
|
|
|
authorizerInfo.setUpdateTime(new Date()); |
|
|
|
|
|
authorizerInfoService.updateTemplate(authorizerInfo); |
|
|
|
|
|
} catch (WxErrorException e) { |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
// 更新状态 |
|
|
|
|
|
authorizerInfo.setTemplateStatus(1); |
|
|
|
|
|
authorizerInfo.setTemplateTime(new Date()); |
|
|
|
|
|
authorizerInfo.setUpdateTime(new Date()); |
|
|
|
|
|
authorizerInfoService.updateTemplate(authorizerInfo); |
|
|
|
|
|
return new ResultData(Result.ERROR, e.getMessage()); |
|
|
|
|
|
|
|
|
// 更新状态 |
|
|
|
|
|
authorizerInfo.setTemplateStatus(EnumWxAuthotizationTemplateStatus.SUCCESS.getCode()); |
|
|
|
|
|
authorizerInfo.setTemplateTime(new Date()); |
|
|
|
|
|
authorizerInfo.setUpdateTime(new Date()); |
|
|
|
|
|
authorizerInfoService.updateTemplate(authorizerInfo); |
|
|
|
|
|
} catch (WxErrorException e) { |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
// 更新状态 |
|
|
|
|
|
authorizerInfo.setTemplateStatus(EnumWxAuthotizationTemplateStatus.Fail.getCode()); |
|
|
|
|
|
authorizerInfo.setTemplateTime(new Date()); |
|
|
|
|
|
authorizerInfo.setUpdateTime(new Date()); |
|
|
|
|
|
authorizerInfoService.updateTemplate(authorizerInfo); |
|
|
|
|
|
return new ResultData(Result.ERROR, e.getMessage()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// 设置成功返回null |
|
|
// 设置成功返回null |
|
|
|