Просмотр исходного кода

Merge branch 'release_toaliyun_real_20230511' of https://git.malls.iformall.com/server/formallProject into release_toaliyun_real_20230511

release_toaliyun_real
winter 3 лет назад
Родитель
Сommit
305d32926f
2 измененных файлов: 23 добавлений и 10 удалений
  1. +5
    -3
      mallinkService/src/main/java/com/iformall/douyin/miniapp/api/TtMaService.java
  2. +18
    -7
      mallinkService/src/main/java/com/iformall/douyin/miniapp/api/impl/TtMaServiceImpl.java

+ 5
- 3
mallinkService/src/main/java/com/iformall/douyin/miniapp/api/TtMaService.java Просмотреть файл

@@ -14,11 +14,13 @@ public interface TtMaService {
/**
* 获取access_token.
*/
String GET_ACCESS_TOKEN_URL = "https://developer.toutiao.com/api/apps/token?grant_type=client_credential&appid=%s&secret=%s";
// String GET_ACCESS_TOKEN_URL = "https://developer.toutiao.com/api/apps/token?grant_type=client_credential&appid=%s&secret=%s";

String JSCODE_TO_SESSION_URL = "https://developer.toutiao.com/api/apps/jscode2session";
String GET_ACCESS_TOKEN_URL = "https://developer.toutiao.com/api/apps/token";

String ORDER_PUSH = "https://developer.toutiao.com/api/apps/order/v2/push";
// String JSCODE_TO_SESSION_URL = "https://developer.toutiao.com/api/apps/jscode2session";
String JSCODE_TO_SESSION_URL = "https://developer.toutiao.com/api/apps/v2/jscode2session";
// String ORDER_PUSH = "https://developer.toutiao.com/api/apps/order/v2/push";

/**
* 获取登录后的session信息.


+ 18
- 7
mallinkService/src/main/java/com/iformall/douyin/miniapp/api/impl/TtMaServiceImpl.java Просмотреть файл

@@ -2,6 +2,7 @@ package com.iformall.douyin.miniapp.api.impl;

import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
@@ -22,6 +23,8 @@ import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;

@@ -101,15 +104,22 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl
Lock lock = this.getWxMaConfig().getAccessTokenLock();
lock.lock();
try {
String url = String.format(this.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(),
this.getWxMaConfig().getSecret());
// String url = String.format(this.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(),
// this.getWxMaConfig().getSecret());
try {
HttpGet httpGet = new HttpGet(url);
HttpPost httpPost = new HttpPost(this.GET_ACCESS_TOKEN_URL);
httpPost.addHeader("Content-Type","application/json");
Map<String,Object> param = new HashMap<>();
param.put("appid",this.getWxMaConfig().getAppid());
param.put("secret",this.getWxMaConfig().getSecret());
param.put("grant_type","client_credential");
httpPost.setEntity(new StringEntity(JSON.toJSONString(param)));
// HttpGet httpGet = new HttpGet(url);
if (this.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpGet.setConfig(config);
httpPost.setConfig(config);
}
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpPost)) {
String resultContent = new BasicResponseHandler().handleResponse(response);
WxError error = WxError.fromJson(resultContent, WxType.MiniApp);
if (error.getErrorCode() != 0) {
@@ -120,7 +130,7 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl

return this.getWxMaConfig().getAccessToken();
} finally {
httpGet.releaseConnection();
httpPost.releaseConnection();
}
} catch (IOException e) {
throw new RuntimeException(e);
@@ -141,7 +151,8 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl
params.put("secret", config.getSecret());
params.put("code", jsCode);

String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
String result =post(this.JSCODE_TO_SESSION_URL,params);
// String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxMaJscode2SessionResult.fromJson(result);
}



Загрузка…
Отмена
Сохранить