Visitar URL original
增加查询小程序可回退的版本 接口 by hywr · Pull Request #2163 · binarywang/WxJava · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f14b88c
添加对话能力(原导购)相关结果 均通过单元测试
May 14, 2021
1c049e4
Merge remote-tracking branch 'origin/develop' into develop
hywr May 14, 2021
32695c7
Merge remote-tracking branch 'origin/develop' into develop
hywr May 17, 2021
aec9387
修改公众号、小程序、企业微信的access token自动刷新逻辑,用于避免当使用secrete误调用第三方平台专属接口的情况下出现循环递…
hywr May 17, 2021
edc935a
1.修复公众号在由第三方平台管理时OAuth2Service授权相关报错问题
hywr May 21, 2021
32028de
Merge remote-tracking branch 'origin/develop' into develop
hywr May 21, 2021
41791eb
1.增加查询小程序可回退的版本 接口
hywr Jun 23, 2021
1611b41
:memo: 更新版本信息
binarywang Jun 2, 2021
5d276b7
:memo: 更新部分信息
binarywang Jun 2, 2021
9279156
:art: 修复单元测试代码
binarywang Jun 3, 2021
933e058
:arrow_up: upgrade guava version
binarywang Jun 3, 2021
1905871
:new: #2142 【企业微信】被动回复消息内容新增任务卡片格式
arthur0201 Jun 4, 2021
d47d687
:arrow_up: Bump httpclient from 4.5 to 4.5.13 (#2143)
dependabot[bot] Jun 4, 2021
953b5f9
:art: 优化部分代码
binarywang Jun 4, 2021
a736621
:art: #2144【企业微信】更新任务卡片消息状态接口参数跟文档保持一致
arthur0201 Jun 7, 2021
d1e8fe3
:new: #2135 【小程序】实现获取 URL Link接口 以及微信电子发票报销方相关接口
mr-xiaoyu Jun 11, 2021
d6d3625
:art: #2155 【企业微信】发送新客户欢迎语接口增加对视频类型的支持,同时修复结构不正确的问题
chutian0124 Jun 21, 2021
4f5be60
:new: #2150 【企业微信】补充完善部分客户联系接口,以及服务商模式外部联系人openid转换接口
chutian0124 Jun 22, 2021
b6092db
:new: #2161 【公众号】微信推送消息类增加群发接口事件相关字段
arthur0201 Jun 23, 2021
e56eb91
1.增加查询小程序可回退的版本 接口
hywr Jun 23, 2021
a6cd1e3
Merge branch 'develop' into develop2
hywr Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1.修复公众号在由第三方平台管理时OAuth2Service授权相关报错问题
2.修复公众号对话能力查询标签列表参数错误
3.第三方平台增加单元测试依赖注入相关类和相关配置示例
  • Loading branch information
hywr committed May 21, 2021
commit edc935a9ffbf6a99d73c607b345ef6583725535e
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public interface WxOAuth2Service {
/**
* <pre>
* 构造oauth2授权的url连接.
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* 详情请见: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
* </pre>
*
* @param redirectUri 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
* @param scope scope
* @param scope scope,静默:snsapi_base, 带信息授权:snsapi_userinfo
* @param state state
* @return url
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.chanjar.weixin.common.service;

import lombok.AllArgsConstructor;
import lombok.experimental.Delegate;

/**
* 微信 oauth2服务 装饰器
*
* @author <a href="https://www.sacoc.cn">广州跨界</a>
*/
@AllArgsConstructor
public class WxOAuth2ServiceDecorator implements WxOAuth2Service {

@Delegate
private final WxOAuth2Service wxOAuth2Service;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;

/**
* 微信导购助手(现在叫对话能力)标签相关接口.
*
* @author <a href="https://www.sacoc.cn">广州跨界-宋心成</a>
* @date 2021/5/13/013
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public List<String> queryGuideBuyerByTag(String account, String openid, Integer
body.put(ACCOUNT, account);
body.put(OPENID, openid);
body.put("push_count", pushCount);
body.put("tag_value", value);
body.put("tag_values", value);
String returnString = this.mpService.post(WxMpApiUrl.Guide.QUERY_GUIDE_BUYER_BY_TAG, body);
return WxGsonBuilder.create().fromJson(GsonParser.parse(returnString).getAsJsonArray("openid_list"),
new TypeToken<List<String>>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package me.chanjar.weixin.open.api;

import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.open.bean.WxOpenCreateResult;
import me.chanjar.weixin.open.bean.WxOpenGetResult;
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
Expand Down Expand Up @@ -330,7 +331,10 @@ public interface WxOpenComponentService {
* @param code the code
* @return the wx mp o auth 2 access token
* @throws WxErrorException the wx error exception
* @see WxMpService#getOAuth2Service()
* @deprecated 2021-05-21: 已修正公众号相关接口,请使用:WxOpenCommpentService.getWxMpServiceByAppid(mpAppId).getOAuth2Service().getAccessToken(code)
*/
@Deprecated
WxOAuth2AccessToken oauth2getAccessToken(String appid, String code) throws WxErrorException;

/**
Expand Down Expand Up @@ -362,7 +366,10 @@ public interface WxOpenComponentService {
* @param scope the scope
* @param state the state
* @return the string
* @see WxMpService#getOAuth2Service()
* @deprecated 2021-05-21: 已修正公众号相关接口,请使用:WxOpenCommpentService.getWxMpServiceByAppid(mpAppId).getOAuth2Service().buildAuthorizationUrl(redirectUri, scope, state)
*/
@Deprecated
String oauth2buildAuthorizationUrl(String appid, String redirectUri, String scope, String state);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package me.chanjar.weixin.open.api.impl;

import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.common.service.WxOAuth2ServiceDecorator;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.open.api.WxOpenComponentService;
import org.apache.commons.lang3.StringUtils;

/**
* 微信 第三方平台对于公众号 oauth2 的实现类
*
* @author <a href="https://www.sacoc.cn">广州跨界</a>
*/
public class WxOpenMpOAuth2ServiceImpl extends WxOAuth2ServiceDecorator {

private final WxOpenComponentService wxOpenComponentService;
private final WxMpConfigStorage wxMpConfigStorage;


public WxOpenMpOAuth2ServiceImpl(WxOpenComponentService wxOpenComponentService, WxOAuth2Service wxOAuth2Service, WxMpConfigStorage wxMpConfigStorage) {
super(wxOAuth2Service);
this.wxOpenComponentService = wxOpenComponentService;
this.wxMpConfigStorage = wxMpConfigStorage;
}

/**
* 第三方平台代公众号发起网页授权
* 文档地址:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Official_Accounts/official_account_website_authorization.html
*
* @param code 微信授权code
* @return 微信用户信息
* @throws WxErrorException 如果微信接口调用失败将抛出此异常
*/
@Override
public WxOAuth2AccessToken getAccessToken(String code) throws WxErrorException {
String url = String.format(
WxOpenComponentService.OAUTH2_ACCESS_TOKEN_URL,
wxMpConfigStorage.getAppId(),
code,
wxOpenComponentService.getWxOpenConfigStorage().getComponentAppId()
);
String responseContent = wxOpenComponentService.get(url);
return WxOAuth2AccessToken.fromJson(responseContent);
}

@Override
public String buildAuthorizationUrl(String redirectUri, String scope, String state) {
return String.format(
WxOpenComponentService.CONNECT_OAUTH2_AUTHORIZE_URL,
wxMpConfigStorage.getAppId(),
URIUtil.encodeURIComponent(redirectUri),
scope,
StringUtils.trimToEmpty(state),
wxOpenComponentService.getWxOpenConfigStorage().getComponentAppId()
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import me.chanjar.weixin.open.bean.mp.FastRegisterResult;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Objects;

/**
Expand All @@ -22,9 +21,11 @@ public class WxOpenMpServiceImpl extends WxMpServiceImpl implements WxOpenMpServ
private String appId;

public WxOpenMpServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMpConfigStorage wxMpConfigStorage) {
// wxOpenComponentService.oauth2getAccessToken(appId)
this.wxOpenComponentService = wxOpenComponentService;
this.appId = appId;
this.wxMpConfigStorage = wxMpConfigStorage;
setOAuth2Service(new WxOpenMpOAuth2ServiceImpl(wxOpenComponentService, getOAuth2Service(), wxMpConfigStorage));
initHttp();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.chanjar.weixin.open.api.impl;

import com.google.inject.Inject;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenMpService;
import me.chanjar.weixin.open.test.ApiTestModule;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

@Guice(modules = ApiTestModule.class)
public class WxOpenMpOAuth2ServiceImplTest {

@Inject
protected WxOpenMpService wxOpenMpService;


@Test
public void buildAuthorizationUrl() {
String url = wxOpenMpService.getOAuth2Service().buildAuthorizationUrl("https://t.aaxp.cn/api/base/mp/showCode", "snsapi_userinfo", "");
System.out.println(url);
}

@Test
public void getAccessToken() throws WxErrorException {
WxOAuth2AccessToken result = wxOpenMpService.getOAuth2Service().getAccessToken("041crm0005iFJL1b2l400I0s0k4crm0z");
System.out.println(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package me.chanjar.weixin.open.test;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.thoughtworks.xstream.XStream;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.open.api.WxOpenMaService;
import me.chanjar.weixin.open.api.WxOpenMpService;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;

public class ApiTestModule implements Module {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private static final String TEST_CONFIG_XML = "test-config.xml";

@Override
public void configure(Binder binder) {
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
if (inputStream == null) {
throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
}

TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);
WxOpenService service = new WxOpenServiceImpl();

service.setWxOpenConfigStorage(config);

binder.bind(TestConfigStorage.class).toInstance(config);
binder.bind(WxOpenService.class).toInstance(service);

if (config.getTestMpAppId() != null && !config.getTestMpAppId().isEmpty()) {
//如果配置了测试公众号,则构建公众号服务依赖
binder.bind(WxOpenMpService.class).toInstance(service.getWxOpenComponentService().getWxMpServiceByAppid(config.getTestMpAppId()));
} else {
log.warn("建议参照参照 test-config-sample.xml 配置测试公众号");
}

if (config.getTestMaAppId() != null && !config.getTestMaAppId().isEmpty()) {
//如果配置了测试小程序,则构建小程序服务依赖
binder.bind(WxOpenMaService.class).toInstance(service.getWxOpenComponentService().getWxMaServiceByAppid(config.getTestMaAppId()));
} else {
log.warn("建议参照参照 test-config-sample.xml 配置测试小程序");
}

} catch (IOException e) {
this.log.error(e.getMessage(), e);
}
}

@SuppressWarnings("unchecked")
private <T> T fromXml(Class<T> clazz, InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", clazz);
xstream.processAnnotations(clazz);
return (T) xstream.fromXML(is);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.chanjar.weixin.open.test;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;

@Getter
@Setter
@XStreamAlias("xml")
public class TestConfigStorage extends WxOpenInMemoryConfigStorage {

private String testMpAppId;

private String testMaAppId;
}
5 changes: 4 additions & 1 deletion weixin-java-open/src/test/resources/test-config.sample.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<xml>
<componentAppId>第三方平台appID</componentAppId>
<componentSecret>第三方平台appsecret</componentSecret>
<componentAppSecret>第三方平台appsecret</componentAppSecret>
<componentVerifyTicket>微信服务器推送过来的ticket</componentVerifyTicket>
<componentToken>第三方平台Token</componentToken>
<componentAesKey>第三方平台EncodingAESKey</componentAesKey>
<appId>测试APPID</appId>
<testMpAppId>测试公众号</testMpAppId>
<testMaAppId>测试小程序</testMaAppId>
</xml>