本文整理了Java中me.chanjar.weixin.mp.api.WxMpService
类的一些代码示例,展示了WxMpService
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMpService
类的具体详情如下:
包路径:me.chanjar.weixin.mp.api.WxMpService
类名称:WxMpService
[英]微信API的Service
[中]微信美国石油学会的服务
代码示例来源:origin: liuweijw/fw-cloud-framework
@Bean
@ConditionalOnMissingBean
public WxMpService wxMpService(WxMpConfigStorage configStorage) {
// WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.okhttp.WxMpServiceImpl();
// WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.jodd.WxMpServiceImpl();
// WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl();
WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(configStorage);
return wxMpService;
}
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
@RequestMapping(value = "/wechat/oauth/authorize", method = GET)
protected void askWeChatWhoTheUserIs(@RequestParam(name = "origin") String origin,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
final String endpointUrl = String.format("%s/wechat/oauth/token", appBaseUri);
final String base64EncodedOrigin =
Base64.getUrlEncoder().encodeToString(origin.getBytes(Charset.forName("UTF-8")));
final String redirect = weChatMpService
.oauth2buildAuthorizationUrl(endpointUrl, "snsapi_base", base64EncodedOrigin);
log.debug("We don't know who u are, redirecting you from {} to {}", origin, redirect);
response.sendRedirect(redirect);
}
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
@SneakyThrows
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
final String code = request.getParameter("code");
WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
return new WeChatMpOAuth2AccessTokenAuthentication(accessToken);
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public File mediaDownload(String mediaId) throws WxErrorException {
return this.wxMpService.execute(
BaseMediaDownloadRequestExecutor.create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()),
MEDIA_GET_URL,
"media_id=" + mediaId);
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
@RequestMapping("/greet")
public String greetUser(@PathVariable String appid, @RequestParam String code, ModelMap map) {
WxMpService mpService = WxMpConfiguration.getMpServices().get(appid);
try {
WxMpOAuth2AccessToken accessToken = mpService.oauth2getAccessToken(code);
WxMpUser user = mpService.oauth2getUserInfo(accessToken, null);
map.put("user", user);
} catch (WxErrorException e) {
e.printStackTrace();
}
return "greet_user";
}
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
@PostConstruct
public void initServices() {
// 代码里 getConfigs()处报错的同学,请注意仔细阅读项目说明,你的IDE需要引入lombok插件!!!!
final List<WxMpProperties.MpConfig> configs = this.properties.getConfigs();
if (configs == null) {
throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!");
}
mpServices = configs.stream().map(a -> {
WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
configStorage.setAppId(a.getAppId());
configStorage.setSecret(a.getSecret());
configStorage.setToken(a.getToken());
configStorage.setAesKey(a.getAesKey());
WxMpService service = new WxMpServiceImpl();
service.setWxMpConfigStorage(configStorage);
routers.put(a.getAppId(), this.newRouter(service));
return service;
}).collect(Collectors.toMap(s -> s.getWxMpConfigStorage().getAppId(), a -> a, (o, n) -> o));
}
代码示例来源:origin: liuweijw/fw-cloud-framework
@PostMapping(produces = "application/xml; charset=UTF-8")
public String post(@RequestBody String requestBody,
@RequestParam("signature") String signature,
@RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce,
@RequestParam(name = "encrypt_type", required = false) String encType,
@RequestParam(name = "msg_signature", required = false) String msgSignature) {
this.logger.info("\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", signature, encType,
msgSignature, timestamp, nonce, requestBody);
if (!this.wxService.checkSignature(timestamp, nonce, signature)) { throw new IllegalArgumentException(
"非法请求,可能属于伪造的请求!"); }
String out = null;
if (encType == null) {
// 明文传输的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
WxMpXmlOutMessage outMessage = this.route(inMessage);
if (outMessage == null) { return ""; }
out = outMessage.toXml();
} else if ("aes".equals(encType)) {
// aes加密的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, this.wxService
.getWxMpConfigStorage(), timestamp, nonce, msgSignature);
this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString());
WxMpXmlOutMessage outMessage = this.route(inMessage);
if (outMessage == null) { return ""; }
out = outMessage.toEncryptedXml(this.wxService.getWxMpConfigStorage());
}
this.logger.debug("\n组装回复信息:{}", out);
return out;
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
URL requestURL = new URL(request.getRequestURL().toString());
String url = WxMpConfiguration.getMpServices().get(appid)
.oauth2buildAuthorizationUrl(
String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appid),
WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
button3.getSubButtons().add(button34);
return WxMpConfiguration.getMpServices().get(appid).getMenuService().menuCreate(menu);
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
/**
* Default {@link WxMpMenuService} provider.
*
* @param wxMpService {@link WxMpService}
* @return {@link WxMpMenuService}
*
* @see WxMpMenuService
*/
@Bean
protected WxMpMenuService wxMpMenuService(WxMpService wxMpService) {
return wxMpService.getMenuService();
}
代码示例来源:origin: liuweijw/fw-cloud-framework
@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr) {
this.logger
.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature, timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) { throw new IllegalArgumentException(
"请求参数非法,请核实!"); }
if (this.wxService.checkSignature(timestamp, nonce, signature)) { return echostr; }
return "非法请求";
}
代码示例来源:origin: liuweijw/fw-cloud-framework
if (isSopeBase) {
log.info("【wxauth.openId】静默登录");
wxMpUser = wxService.getUserService().userInfo(openId);
} else {
wxMpOAuth2AccessToken = wxService.oauth2refreshAccessToken(refreshToken);
log.info("【wxauth.openId】主动登录");
wxMpUser = wxService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
/**
* Default {@link WxMpTemplateMsgService} provider.
*
* @param wxMpService {@link WxMpService}
* @return {@link WxMpTemplateMsgService}
*
* @see WxMpTemplateMsgService
*/
@Bean
protected WxMpTemplateMsgService wxMpTemplateMsgService(WxMpService wxMpService) {
return wxMpService.getTemplateMsgService();
}
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
/**
* Default {@link WxMpKefuService} provider.
*
* @param wxMpService {@link WxMpService}
* @return {@link WxMpKefuService}
*
* @see WxMpKefuService
*/
@Bean
protected WxMpKefuService wxMpKefuService(WxMpService wxMpService) {
return wxMpService.getKefuService();
}
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
/**
* Default {@link WxMpUserService} provider.
*
* @param wxMpService {@link WxMpService}
* @return {@link WxMpUserService}
*
* @see WxMpUserService
*/
@Bean
protected WxMpUserService wxMpUserService(WxMpService wxMpService) {
return wxMpService.getUserService();
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public boolean sendSubscribeMessage(WxMpSubscribeMessage message) throws WxErrorException {
if (message.getTemplateId() == null) {
message.setTemplateId(this.wxMpService.getWxMpConfigStorage().getTemplateId());
}
String responseContent = this.wxMpService.post(SEND_MESSAGE_URL, message.toJson());
return responseContent != null;
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public String subscribeMsgAuthorizationUrl(String redirectURI, int scene, String reserved) {
WxMpConfigStorage storage = this.wxMpService.getWxMpConfigStorage();
return String.format(SUBSCRIBE_MESSAGE_AUTHORIZE_URL,
storage.getAppId(), scene, storage.getTemplateId(), URIUtil.encodeURIComponent(redirectURI), reserved);
}
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
/**
* see <a href="http://admin.wechat.com/wiki/index.php?title=JS_SDK_DOCUMENT#Step_3:_Inject_Correct_Authentication_Configuration_via_the_config_API">
* Inject Correct Authentication Configuration via the config API
* </a>.
*
* @param url the URL to signature
* @return {@link WxJsapiSignature}
* @throws WxErrorException 5XX
*/
@RequestMapping(value = "/wechat/mp/js/config", method = GET)
protected WxJsapiSignature askForConfig(@RequestParam(name = "url") String url)
throws WxErrorException {
return weChatMpService.createJsapiSignature(url);
}
代码示例来源:origin: yjjdick/sdb-mall
@Bean
public Object services() {
mpServices = this.properties.getConfigs()
.stream()
.map(a -> {
WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
configStorage.setAppId(a.getAppId());
configStorage.setSecret(a.getSecret());
configStorage.setToken(a.getToken());
configStorage.setAesKey(a.getAesKey());
WxMpService service = new WxMpServiceImpl();
service.setWxMpConfigStorage(configStorage);
routers.put(a.getAppId(), this.newRouter(service));
return service;
}).collect(Collectors.toMap(s -> s.getWxMpConfigStorage().getAppId(), a -> a));
return Boolean.TRUE;
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
if (!wxService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
} else if ("aes".equalsIgnoreCase(encType)) {
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(),
timestamp, nonce, msgSignature);
this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString());
out = outMessage.toEncryptedXml(wxService.getWxMpConfigStorage());
代码示例来源:origin: binarywang/WxJava
@Override
public InputStream materialImageOrVoiceDownload(String mediaId) throws WxErrorException {
return this.wxMpService.execute(MaterialVoiceAndImageDownloadRequestExecutor
.create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), MATERIAL_GET_URL, mediaId);
}
内容来源于网络,如有侵权,请联系作者删除!