Selaa lähdekoodia

🐛 #1087 修复长链接转短链接接口中含有特殊字符导致微信access_token失效的问题

master
Binary Wang 5 vuotta sitten
vanhempi
commit
db638dd8b1
2 muutettua tiedostoa jossa 17 lisäystä ja 4 poistoa
  1. +6
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java
  2. +11
    -4
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java

+ 6
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java Näytä tiedosto

@@ -145,6 +145,12 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH

@Override
public String shortUrl(String longUrl) throws WxErrorException {
if (longUrl.contains("&access_token=")) {
throw new WxErrorException(WxError.builder().errorCode(-1)
.errorMsg("要转换的网址中存在非法字符{&access_token=},会导致微信接口报错,属于微信bug,请调整地址,否则不建议使用此方法!")
.build());
}

JsonObject o = new JsonObject();
o.addProperty("action", "long2short");
o.addProperty("long_url", longUrl);


+ 11
- 4
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java Näytä tiedosto

@@ -6,21 +6,28 @@ import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.*;
import org.testng.annotations.*;

import static org.assertj.core.api.Assertions.assertThat;

/**
* 测试短连接
*
* @author chanjarster
*/
@Test(groups = "shortURLAPI")
@Test
@Guice(modules = ApiTestModule.class)
public class WxMpShortUrlAPITest {

@Inject
protected WxMpService wxService;

public void testShortUrl() throws WxErrorException {
String shortUrl = this.wxService.shortUrl("www.baidu.com");
Assert.assertNotNull(shortUrl);
String shortUrl = this.wxService.shortUrl("http://www.baidu.com/test?access_token=123");
assertThat(shortUrl).isNotEmpty();
System.out.println(shortUrl);
}

@Test(expectedExceptions = WxErrorException.class)
public void testShortUrl_with_exceptional_url() throws WxErrorException {
this.wxService.shortUrl("http://www.baidu.com/test?redirect_count=1&access_token=123");
}

}

Ladataan…
Peruuta
Tallenna