mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
🎨 #1897 【小程序】接口请求地址的域名增加自定义设置的支持
This commit is contained in:
parent
584c7ac354
commit
87431f3ffe
@ -1,13 +1,14 @@
|
|||||||
package cn.binarywang.wx.miniapp.api;
|
package cn.binarywang.wx.miniapp.api;
|
||||||
|
|
||||||
import cn.binarywang.wx.miniapp.bean.*;
|
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaUpdatableMsg;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
|
||||||
* 消息发送接口
|
* 消息发送接口
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
*/
|
*/
|
||||||
|
@ -243,6 +243,10 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
|||||||
}
|
}
|
||||||
String accessToken = getAccessToken(false);
|
String accessToken = getAccessToken(false);
|
||||||
|
|
||||||
|
if(StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl())){
|
||||||
|
uri = uri.replace("https://api.weixin.qq.com",this.getWxMaConfig().getApiHostUrl() );
|
||||||
|
}
|
||||||
|
|
||||||
String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken;
|
String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -22,7 +22,8 @@ public class WxMaPubTemplateTitleListResult implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class TemplateItem {
|
public static class TemplateItem implements Serializable {
|
||||||
|
private static final long serialVersionUID = 6888726696879905332L;
|
||||||
|
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package cn.binarywang.wx.miniapp.config;
|
package cn.binarywang.wx.miniapp.config;
|
||||||
|
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
|
|
||||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||||
|
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序配置
|
* 小程序配置
|
||||||
*
|
*
|
||||||
@ -219,4 +219,19 @@ public interface WxMaConfig {
|
|||||||
*/
|
*/
|
||||||
boolean autoRefreshToken();
|
boolean autoRefreshToken();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置自定义的apiHost地址
|
||||||
|
* 具体取值,可以参考https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Interface_field_description.html
|
||||||
|
*
|
||||||
|
* @param apiHostUrl api域名地址
|
||||||
|
*/
|
||||||
|
void setApiHostUrl(String apiHostUrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自定义的apiHost地址,用于替换原请求中的https://api.weixin.qq.com
|
||||||
|
* 具体取值,可以参考https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Interface_field_description.html
|
||||||
|
*
|
||||||
|
* @return 自定义的api域名地址
|
||||||
|
*/
|
||||||
|
String getApiHostUrl();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.config.impl;
|
|||||||
|
|
||||||
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
||||||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
||||||
|
import lombok.Getter;
|
||||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
*
|
*
|
||||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public class WxMaDefaultConfigImpl implements WxMaConfig {
|
public class WxMaDefaultConfigImpl implements WxMaConfig {
|
||||||
protected volatile String appid;
|
protected volatile String appid;
|
||||||
protected volatile String token;
|
protected volatile String token;
|
||||||
@ -49,6 +51,7 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
|
|||||||
protected volatile Lock jsapiTicketLock = new ReentrantLock();
|
protected volatile Lock jsapiTicketLock = new ReentrantLock();
|
||||||
protected volatile Lock cardApiTicketLock = new ReentrantLock();
|
protected volatile Lock cardApiTicketLock = new ReentrantLock();
|
||||||
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
|
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
|
||||||
|
private String apiHostUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会过期的数据提前过期时间,默认预留200秒的时间
|
* 会过期的数据提前过期时间,默认预留200秒的时间
|
||||||
@ -124,7 +127,6 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
|
|||||||
this.jsapiTicketExpiresTime = expiresAheadInMillis(expiresInSeconds);
|
this.jsapiTicketExpiresTime = expiresAheadInMillis(expiresInSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCardApiTicket() {
|
public String getCardApiTicket() {
|
||||||
return this.cardApiTicket;
|
return this.cardApiTicket;
|
||||||
@ -274,6 +276,11 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApiHostUrl(String apiHostUrl) {
|
||||||
|
this.apiHostUrl = apiHostUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAppid() {
|
public String getAppid() {
|
||||||
return appid;
|
return appid;
|
||||||
|
Loading…
Reference in New Issue
Block a user