me.chanjar.weixin.mp.api.WxMpService.getWxMpConfigStorage()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(546)

本文整理了Java中me.chanjar.weixin.mp.api.WxMpService.getWxMpConfigStorage()方法的一些代码示例,展示了WxMpService.getWxMpConfigStorage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMpService.getWxMpConfigStorage()方法的具体详情如下:
包路径:me.chanjar.weixin.mp.api.WxMpService
类名称:WxMpService
方法名:getWxMpConfigStorage

WxMpService.getWxMpConfigStorage介绍

[英]获取WxMpConfigStorage 对象.
[中]获取WxMpConfigStorage对象.

代码示例

代码示例来源: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: binarywang/WxJava

@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: binarywang/weixin-java-mp-demo-springboot

} 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: 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: yjjdick/sdb-mall

} else if ("aes".equalsIgnoreCase(encType)) {
  WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(),
    timestamp, nonce, msgSignature);
  log.info("\n消息解密后内容为:\n{} ", inMessage.toString());
  out = outMessage.toEncryptedXml(wxService.getWxMpConfigStorage());

代码示例来源:origin: com.github.binarywang/weixin-java-mp

public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
 final TicketType type = TicketType.WX_CARD;
 Lock lock = getWxMpService().getWxMpConfigStorage().getTicketLock(type);
 try {
  lock.lock();
   this.getWxMpService().getWxMpConfigStorage().expireTicket(type);
  if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) {
   String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor
    .create(this.getWxMpService().getRequestHttp()), CARD_GET_TICKET, null);
   String cardApiTicket = tmpJsonObject.get("ticket").getAsString();
   int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
   this.getWxMpService().getWxMpConfigStorage().updateTicket(type, cardApiTicket, expiresInSeconds);
 return this.getWxMpService().getWxMpConfigStorage().getTicket(type);

代码示例来源:origin: binarywang/WxJava

public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
 final TicketType type = TicketType.WX_CARD;
 Lock lock = getWxMpService().getWxMpConfigStorage().getTicketLock(type);
 try {
  lock.lock();
   this.getWxMpService().getWxMpConfigStorage().expireTicket(type);
  if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) {
   String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor
    .create(this.getWxMpService().getRequestHttp()), CARD_GET_TICKET, null);
   String cardApiTicket = tmpJsonObject.get("ticket").getAsString();
   int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
   this.getWxMpService().getWxMpConfigStorage().updateTicket(type, cardApiTicket, expiresInSeconds);
 return this.getWxMpService().getWxMpConfigStorage().getTicket(type);

代码示例来源: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: com.github.binarywang/weixin-java-mp

@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);
}

代码示例来源: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);
}

代码示例来源:origin: binarywang/WxJava

@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: 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: 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: binarywang/WxJava

@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: 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;
}

相关文章