|
|
@@ -14,6 +14,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import com.etotem.cfc.service.api.WechatServiceInterface;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Base64;
|
|
|
@@ -141,7 +142,14 @@ public class WechatService implements WechatServiceInterface {
|
|
|
* 获取公众号OAuth2授权URL
|
|
|
*/
|
|
|
public String getOAuth2Url(String redirectUri) {
|
|
|
- String encodedUri = URLEncoder.encode(redirectUri, StandardCharsets.UTF_8);
|
|
|
+ String encodedUri;
|
|
|
+ try {
|
|
|
+ encodedUri = URLEncoder.encode(redirectUri, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ // UTF-8 在 JVM 中始终可用,此异常实际不会发生
|
|
|
+ log.error("OAuth2 redirectUri 编码失败", e);
|
|
|
+ encodedUri = redirectUri;
|
|
|
+ }
|
|
|
return String.format(
|
|
|
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect",
|
|
|
appid, encodedUri);
|