|
@ -1,5 +1,6 @@ |
|
|
package com.qs.serve.modules.wx.api; |
|
|
package com.qs.serve.modules.wx.api; |
|
|
|
|
|
|
|
|
|
|
|
import com.qs.serve.modules.wx.common.conf.WxMpConfig; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import me.chanjar.weixin.common.api.WxConsts; |
|
|
import me.chanjar.weixin.common.api.WxConsts; |
|
|
import me.chanjar.weixin.common.bean.menu.WxMenu; |
|
|
import me.chanjar.weixin.common.bean.menu.WxMenu; |
|
@ -8,6 +9,7 @@ import me.chanjar.weixin.common.error.WxErrorException; |
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; |
|
|
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; |
|
|
import me.chanjar.weixin.mp.bean.menu.WxMpMenu; |
|
|
import me.chanjar.weixin.mp.bean.menu.WxMpMenu; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
@ -27,7 +29,8 @@ import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType; |
|
|
//@RestController
|
|
|
//@RestController
|
|
|
//@RequestMapping("/api/mp/menu/{appid}")
|
|
|
//@RequestMapping("/api/mp/menu/{appid}")
|
|
|
public class WxMpMenuApi { |
|
|
public class WxMpMenuApi { |
|
|
private final WxMpService wxService; |
|
|
@Autowired(required = false) |
|
|
|
|
|
private WxMpConfig wxMpConfig; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 自定义菜单创建接口 |
|
|
* 自定义菜单创建接口 |
|
@ -40,7 +43,7 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@PostMapping("/create") |
|
|
@PostMapping("/create") |
|
|
public String menuCreate(@PathVariable String appid, @RequestBody WxMenu menu) throws WxErrorException { |
|
|
public String menuCreate(@PathVariable String appid, @RequestBody WxMenu menu) throws WxErrorException { |
|
|
return this.wxService.switchoverTo(appid).getMenuService().menuCreate(menu); |
|
|
return wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().menuCreate(menu); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//@GetMapping("/createByData")
|
|
|
//@GetMapping("/createByData")
|
|
@ -89,7 +92,7 @@ public class WxMpMenuApi { |
|
|
if (servletRequestAttributes != null) { |
|
|
if (servletRequestAttributes != null) { |
|
|
HttpServletRequest request = servletRequestAttributes.getRequest(); |
|
|
HttpServletRequest request = servletRequestAttributes.getRequest(); |
|
|
URL requestURL = new URL(request.getRequestURL().toString()); |
|
|
URL requestURL = new URL(request.getRequestURL().toString()); |
|
|
String url = this.wxService.switchoverTo(appid).getOAuth2Service().buildAuthorizationUrl( |
|
|
String url = wxMpConfig.wxMpService().switchoverTo(appid).getOAuth2Service().buildAuthorizationUrl( |
|
|
String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appid), |
|
|
String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appid), |
|
|
WxConsts.OAuth2Scope.SNSAPI_USERINFO, null); |
|
|
WxConsts.OAuth2Scope.SNSAPI_USERINFO, null); |
|
|
button34.setUrl(url); |
|
|
button34.setUrl(url); |
|
@ -100,8 +103,8 @@ public class WxMpMenuApi { |
|
|
button3.getSubButtons().add(button33); |
|
|
button3.getSubButtons().add(button33); |
|
|
button3.getSubButtons().add(button34); |
|
|
button3.getSubButtons().add(button34); |
|
|
|
|
|
|
|
|
this.wxService.switchover(appid); |
|
|
wxMpConfig.wxMpService().switchover(appid); |
|
|
return this.wxService.getMenuService().menuCreate(menu); |
|
|
return wxMpConfig.wxMpService().getMenuService().menuCreate(menu); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -115,7 +118,7 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@PostMapping("/createByJson") |
|
|
@PostMapping("/createByJson") |
|
|
public String menuCreate(@PathVariable String appid, @RequestBody String json) throws WxErrorException { |
|
|
public String menuCreate(@PathVariable String appid, @RequestBody String json) throws WxErrorException { |
|
|
return this.wxService.switchoverTo(appid).getMenuService().menuCreate(json); |
|
|
return wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().menuCreate(json); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -126,7 +129,7 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@GetMapping("/delete") |
|
|
@GetMapping("/delete") |
|
|
public void menuDelete(@PathVariable String appid) throws WxErrorException { |
|
|
public void menuDelete(@PathVariable String appid) throws WxErrorException { |
|
|
this.wxService.switchoverTo(appid).getMenuService().menuDelete(); |
|
|
wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().menuDelete(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -138,7 +141,7 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@GetMapping("/delete/{menuId}") |
|
|
@GetMapping("/delete/{menuId}") |
|
|
public void menuDelete(@PathVariable String appid, @PathVariable String menuId) throws WxErrorException { |
|
|
public void menuDelete(@PathVariable String appid, @PathVariable String menuId) throws WxErrorException { |
|
|
this.wxService.switchoverTo(appid).getMenuService().menuDelete(menuId); |
|
|
wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().menuDelete(menuId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -149,7 +152,7 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@GetMapping("/get") |
|
|
@GetMapping("/get") |
|
|
public WxMpMenu menuGet(@PathVariable String appid) throws WxErrorException { |
|
|
public WxMpMenu menuGet(@PathVariable String appid) throws WxErrorException { |
|
|
return this.wxService.switchoverTo(appid).getMenuService().menuGet(); |
|
|
return wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().menuGet(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -162,7 +165,7 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@GetMapping("/menuTryMatch/{userid}") |
|
|
@GetMapping("/menuTryMatch/{userid}") |
|
|
public WxMenu menuTryMatch(@PathVariable String appid, @PathVariable String userid) throws WxErrorException { |
|
|
public WxMenu menuTryMatch(@PathVariable String appid, @PathVariable String userid) throws WxErrorException { |
|
|
return this.wxService.switchoverTo(appid).getMenuService().menuTryMatch(userid); |
|
|
return wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().menuTryMatch(userid); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -182,6 +185,6 @@ public class WxMpMenuApi { |
|
|
*/ |
|
|
*/ |
|
|
@GetMapping("/getSelfMenuInfo") |
|
|
@GetMapping("/getSelfMenuInfo") |
|
|
public WxMpGetSelfMenuInfoResult getSelfMenuInfo(@PathVariable String appid) throws WxErrorException { |
|
|
public WxMpGetSelfMenuInfoResult getSelfMenuInfo(@PathVariable String appid) throws WxErrorException { |
|
|
return this.wxService.switchoverTo(appid).getMenuService().getSelfMenuInfo(); |
|
|
return wxMpConfig.wxMpService().switchoverTo(appid).getMenuService().getSelfMenuInfo(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|