| @@ -21,7 +21,7 @@ import java.util.List; | |||
| * @author Stormeye | |||
| */ | |||
| @RestController | |||
| @RequestMapping("/wx/{account}/mem") | |||
| @RequestMapping("/wx/{appId}/mem") | |||
| public class WxMemController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @@ -29,8 +29,8 @@ public class WxMemController { | |||
| private WxMpManager wxMpManager; | |||
| @GetMapping("/syncAccountFansList") | |||
| public ResultData syncAccountFansList(@PathVariable String account) throws WxErrorException { | |||
| final WxMpService wxService = wxMpManager.getMpService(account); | |||
| public ResultData syncAccountFansList(@PathVariable String appId) throws WxErrorException { | |||
| final WxMpService wxService = wxMpManager.getMpService(appId); | |||
| WxMpUserList mpUserList = wxService.getUserService().userList(null); | |||
| logger.info(mpUserList.toString()); | |||
| @@ -22,7 +22,7 @@ import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType; | |||
| * @author Stormeye | |||
| */ | |||
| @RestController | |||
| @RequestMapping("/wx/menu/{account}") | |||
| @RequestMapping("/wx/menu/{appId}") | |||
| public class WxMenuController { | |||
| @Autowired | |||
| @@ -39,12 +39,12 @@ public class WxMenuController { | |||
| * @return 如果是个性化菜单,则返回menuid,否则返回null | |||
| */ | |||
| @PostMapping("/create") | |||
| public String menuCreate(@PathVariable String account, @RequestBody WxMenu menu) throws WxErrorException { | |||
| return wxMpManager.getMpService(account).getMenuService().menuCreate(menu); | |||
| public String menuCreate(@PathVariable String appId, @RequestBody WxMenu menu) throws WxErrorException { | |||
| return wxMpManager.getMpService(appId).getMenuService().menuCreate(menu); | |||
| } | |||
| @GetMapping("/create") | |||
| public String menuCreateSample(@PathVariable String account) throws WxErrorException, MalformedURLException { | |||
| public String menuCreateSample(@PathVariable String appId) throws WxErrorException, MalformedURLException { | |||
| WxMenu menu = new WxMenu(); | |||
| WxMenuButton button1 = new WxMenuButton(); | |||
| button1.setType(MenuButtonType.CLICK); | |||
| @@ -89,9 +89,9 @@ public class WxMenuController { | |||
| if (servletRequestAttributes != null) { | |||
| HttpServletRequest request = servletRequestAttributes.getRequest(); | |||
| URL requestURL = new URL(request.getRequestURL().toString()); | |||
| String url = wxMpManager.getMpService(account) | |||
| String url = wxMpManager.getMpService(appId) | |||
| .oauth2buildAuthorizationUrl( | |||
| String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), account), | |||
| String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appId), | |||
| WxConsts.OAuth2Scope.SNSAPI_USERINFO, null); | |||
| button34.setUrl(url); | |||
| } | |||
| @@ -101,7 +101,7 @@ public class WxMenuController { | |||
| button3.getSubButtons().add(button33); | |||
| button3.getSubButtons().add(button34); | |||
| return wxMpManager.getMpService(account).getMenuService().menuCreate(menu); | |||
| return wxMpManager.getMpService(appId).getMenuService().menuCreate(menu); | |||
| } | |||
| /** | |||
| @@ -116,8 +116,8 @@ public class WxMenuController { | |||
| * @return 如果是个性化菜单,则返回menuid,否则返回null | |||
| */ | |||
| @PostMapping("/createByJson") | |||
| public String menuCreate(@PathVariable String account, @RequestBody String json) throws WxErrorException { | |||
| return wxMpManager.getMpService(account).getMenuService().menuCreate(json); | |||
| public String menuCreate(@PathVariable String appId, @RequestBody String json) throws WxErrorException { | |||
| return wxMpManager.getMpService(appId).getMenuService().menuCreate(json); | |||
| } | |||
| /** | |||
| @@ -127,8 +127,8 @@ public class WxMenuController { | |||
| * </pre> | |||
| */ | |||
| @GetMapping("/delete") | |||
| public void menuDelete(@PathVariable String account) throws WxErrorException { | |||
| wxMpManager.getMpService(account).getMenuService().menuDelete(); | |||
| public void menuDelete(@PathVariable String appId) throws WxErrorException { | |||
| wxMpManager.getMpService(appId).getMenuService().menuDelete(); | |||
| } | |||
| /** | |||
| @@ -140,8 +140,8 @@ public class WxMenuController { | |||
| * @param menuId 个性化菜单的menuid | |||
| */ | |||
| @GetMapping("/delete/{menuId}") | |||
| public void menuDelete(@PathVariable String account, @PathVariable String menuId) throws WxErrorException { | |||
| wxMpManager.getMpService(account).getMenuService().menuDelete(menuId); | |||
| public void menuDelete(@PathVariable String appId, @PathVariable String menuId) throws WxErrorException { | |||
| wxMpManager.getMpService(appId).getMenuService().menuDelete(menuId); | |||
| } | |||
| /** | |||
| @@ -151,8 +151,8 @@ public class WxMenuController { | |||
| * </pre> | |||
| */ | |||
| @GetMapping("/get") | |||
| public WxMpMenu menuGet(@PathVariable String account) throws WxErrorException { | |||
| return wxMpManager.getMpService(account).getMenuService().menuGet(); | |||
| public WxMpMenu menuGet(@PathVariable String appId) throws WxErrorException { | |||
| return wxMpManager.getMpService(appId).getMenuService().menuGet(); | |||
| } | |||
| /** | |||
| @@ -164,8 +164,8 @@ public class WxMenuController { | |||
| * @param userid 可以是粉丝的OpenID,也可以是粉丝的微信号。 | |||
| */ | |||
| @GetMapping("/menuTryMatch/{userid}") | |||
| public WxMenu menuTryMatch(@PathVariable String account, @PathVariable String userid) throws WxErrorException { | |||
| return wxMpManager.getMpService(account).getMenuService().menuTryMatch(userid); | |||
| public WxMenu menuTryMatch(@PathVariable String appId, @PathVariable String userid) throws WxErrorException { | |||
| return wxMpManager.getMpService(appId).getMenuService().menuTryMatch(userid); | |||
| } | |||
| /** | |||
| @@ -184,7 +184,7 @@ public class WxMenuController { | |||
| * </pre> | |||
| */ | |||
| @GetMapping("/getSelfMenuInfo") | |||
| public WxMpGetSelfMenuInfoResult getSelfMenuInfo(@PathVariable String account) throws WxErrorException { | |||
| return wxMpManager.getMpService(account).getMenuService().getSelfMenuInfo(); | |||
| public WxMpGetSelfMenuInfoResult getSelfMenuInfo(@PathVariable String appId) throws WxErrorException { | |||
| return wxMpManager.getMpService(appId).getMenuService().getSelfMenuInfo(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,76 @@ | |||
| package com.iformall.mp.controller; | |||
| import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; | |||
| import com.google.common.collect.Lists; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.mp.manager.WxMpManager; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUserList; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplate; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.PathVariable; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| @RestController | |||
| @RequestMapping("/wx/{appId}/template") | |||
| public class WxMpTemplateController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxMpManager wxMpManager; | |||
| @GetMapping("/send") | |||
| public ResultData syncAccountFansList(@PathVariable String appId) throws WxErrorException { | |||
| final WxMpService wxService = wxMpManager.getMpService(appId); | |||
| // 审核结果通知 SxhGTL6AlcYtbc4nEYxcS4zoGRzTiUr9KEscvpEItQw | |||
| // {{first.DATA}} | |||
| // 审核状态:{{keyword1.DATA}} | |||
| // 活动名称:{{keyword2.DATA}} | |||
| // 活动时间:{{keyword3.DATA}} | |||
| // 活动地点:{{keyword4.DATA}} | |||
| // {{remark.DATA}} | |||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | |||
| String templateId = "SxhGTL6AlcYtbc4nEYxcS4zoGRzTiUr9KEscvpEItQw"; | |||
| WxMpTemplateMessage.MiniProgram miniprogram = new WxMpTemplateMessage.MiniProgram(); | |||
| miniprogram.setAppid("wxea71200db93d756b"); | |||
| miniprogram.setPagePath("pages/index/index"); | |||
| miniprogram.setUsePath(true); | |||
| WxMpTemplateMessage msg = WxMpTemplateMessage.builder() | |||
| .toUser("o8iB81ZUK0SOR0ZOp6t9Q1GCMYuM") | |||
| .templateId(templateId) | |||
| .miniProgram(miniprogram) | |||
| .data(Lists.newArrayList( | |||
| new WxMpTemplateData("first", "恭喜您,您的小程序\"富茂客官开发\"审核已通过", "#173177"), | |||
| new WxMpTemplateData("keyword1", "审核已通过", "#173177"), | |||
| new WxMpTemplateData("keyword2", "提交审核已通过", "#173177"), | |||
| new WxMpTemplateData("keyword3", dateFormat.format(new Date()), "#173177"), | |||
| new WxMpTemplateData("keyword4", "地点", "#173177"), | |||
| new WxMpTemplateData("remark", "test", "#173177") | |||
| )) | |||
| .build(); | |||
| String rest = wxService.getTemplateMsgService().sendTemplateMsg(msg); | |||
| logger.info(rest); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -5,7 +5,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; | |||
| import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage; | |||
| import com.google.common.collect.Lists; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.vo.WxPayOrderVo; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -92,7 +91,6 @@ public class UserUnionIdSchedule { | |||
| * 根据payOrder发送模板消息 | |||
| * @param payOrderVo | |||
| */ | |||
| /* | |||
| public void sendUniformMessage(WxPayOrderVo payOrderVo) { | |||
| if(StringUtils.isBlank(payOrderVo.getOpenId())) { | |||
| return; | |||
| @@ -107,6 +105,14 @@ public class UserUnionIdSchedule { | |||
| // 卡券号码:{{keyword2.DATA}} | |||
| // 核销时间:{{keyword3.DATA}} | |||
| // {{remark.DATA}} | |||
| // 审核结果通知 SxhGTL6AlcYtbc4nEYxcS4zoGRzTiUr9KEscvpEItQw | |||
| // {{first.DATA}} | |||
| // 审核状态:{{keyword1.DATA}} | |||
| // 活动名称:{{keyword2.DATA}} | |||
| // 活动时间:{{keyword3.DATA}} | |||
| // 活动地点:{{keyword4.DATA}} | |||
| // {{remark.DATA}} | |||
| // | |||
| // | |||
| String template_id = "p6pwzZN9GVJq11j2zh72EEhIn5fAIa6oQBBOjqVt8-U"; | |||
| @@ -132,8 +138,7 @@ public class UserUnionIdSchedule { | |||
| )) | |||
| .emphasisKeyword("keyword1.DATA") | |||
| .build(); | |||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(payOrderVo.getAppId()); | |||
| WxMaService wxMaService = MaUtil.getWeappService(appInfo); | |||
| WxMaService wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(payOrderVo.getAppId()); | |||
| try { | |||
| wxMaService.getMsgService().sendUniformMsg(templateMessage); | |||
| @@ -141,5 +146,5 @@ public class UserUnionIdSchedule { | |||
| logger.error("支付通知测试: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); | |||
| } | |||
| }*/ | |||
| } | |||
| } | |||