拉卡拉分账调试修正
This commit is contained in:
parent
cd280458f0
commit
39e86f5668
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||||
|
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||||
|
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||||
|
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||||
|
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.suisung.mall.common.utils;
|
||||||
|
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class RestTemplateHttpUtil {
|
||||||
|
private static final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送 GET 请求
|
||||||
|
*
|
||||||
|
* @param url 请求的 URL
|
||||||
|
* @param responseType 响应的类型
|
||||||
|
* @param <T> 泛型类型
|
||||||
|
* @return 响应对象
|
||||||
|
*/
|
||||||
|
public static <T> T sendGet(String url, Class<T> responseType) {
|
||||||
|
ResponseEntity<T> response = restTemplate.getForEntity(url, responseType);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送 GET 请求,带请求参数
|
||||||
|
*
|
||||||
|
* @param url 请求的 URL
|
||||||
|
* @param uriVariables 请求参数
|
||||||
|
* @param responseType 响应的类型
|
||||||
|
* @param <T> 泛型类型
|
||||||
|
* @return 响应对象
|
||||||
|
*/
|
||||||
|
public static <T> T sendGet(String url, Map<String, ?> uriVariables, Class<T> responseType) {
|
||||||
|
ResponseEntity<T> response = restTemplate.getForEntity(url, responseType, uriVariables);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送带 header 的 GET 请求
|
||||||
|
*
|
||||||
|
* @param url 请求的 URL
|
||||||
|
* @param headers 请求头
|
||||||
|
* @param responseType 响应的类型
|
||||||
|
* @param <T> 泛型类型
|
||||||
|
* @return 响应对象
|
||||||
|
*/
|
||||||
|
public static <T> T sendGetWithHeader(String url, Map<String, String> headers, Class<T> responseType) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
if (headers != null) {
|
||||||
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
|
httpHeaders.add(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HttpEntity<?> entity = new HttpEntity<>(httpHeaders);
|
||||||
|
ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, entity, responseType);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送带 header 的 POST 请求
|
||||||
|
*
|
||||||
|
* @param url 请求的 URL
|
||||||
|
* @param headers 请求头
|
||||||
|
* @param requestBody 请求体
|
||||||
|
* @param responseType 响应的类型
|
||||||
|
* @param <T> 泛型类型
|
||||||
|
* @return 响应对象
|
||||||
|
*/
|
||||||
|
public static <T> T sendPost(String url, Map<String, String> headers, Object requestBody, Class<T> responseType) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
if (headers != null) {
|
||||||
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
|
httpHeaders.add(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
HttpEntity<Object> entity = new HttpEntity<>(requestBody, httpHeaders);
|
||||||
|
ResponseEntity<T> response = restTemplate.postForEntity(url, entity, responseType);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送带 header 的 POST form-data 请求
|
||||||
|
* @param url 请求的 URL
|
||||||
|
* @param headers 请求头
|
||||||
|
* @param formData form-data 数据
|
||||||
|
* @param responseType 响应的类型
|
||||||
|
* @param <T> 泛型类型
|
||||||
|
* @return 响应对象
|
||||||
|
*/
|
||||||
|
public static <T> T sendPostFormData(String url, Map<String, String> headers, Map<String, String> formData, Class<T> responseType) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
if (headers != null) {
|
||||||
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
|
httpHeaders.add(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
|
||||||
|
if (formData != null) {
|
||||||
|
for (Map.Entry<String, String> entry : formData.entrySet()) {
|
||||||
|
multiValueMap.add(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(multiValueMap, httpHeaders);
|
||||||
|
ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, entity, responseType);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||||
|
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||||
|
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||||
|
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||||
|
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.suisung.mall.shop.lakala.controller;
|
||||||
|
|
||||||
|
import com.suisung.mall.common.service.impl.BaseControllerImpl;
|
||||||
|
import com.suisung.mall.shop.lakala.service.impl.CommonService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Api(tags = "拉卡拉商户进件控制器")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/shop/lakala/tk")
|
||||||
|
public class LklTkController extends BaseControllerImpl {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CommonService commonService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "请求获取token(商户进件)", notes = "请求获取token(商户进件)")
|
||||||
|
@RequestMapping(value = "/token", method = RequestMethod.POST)
|
||||||
|
public String getLklTkAuthorization() {
|
||||||
|
return commonService.getLklTkAuthorization();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "请求获取token(商户进件)", notes = "请求获取token(商户进件)")
|
||||||
|
@RequestMapping(value = "/token", method = RequestMethod.POST)
|
||||||
|
public String getLklTkAuthorization1() {
|
||||||
|
return commonService.getLklTkAuthorization();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||||
|
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||||
|
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||||
|
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||||
|
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.suisung.mall.shop.lakala.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.suisung.mall.common.utils.RestTemplateHttpUtil;
|
||||||
|
import com.suisung.mall.core.web.service.RedisService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CommonService {
|
||||||
|
|
||||||
|
@Value("${lakala.tk.server_url}")
|
||||||
|
private String serverUrl;
|
||||||
|
|
||||||
|
@Value("${lakala.tk.client_id}")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
@Value("${lakala.tk.client_secret}")
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
|
protected String buildLklTkUrl(String urlPath){
|
||||||
|
return serverUrl + urlPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求获取token(商户进件)
|
||||||
|
*
|
||||||
|
* @return AuthorizationKey
|
||||||
|
*/
|
||||||
|
public String getLklTkAuthorization() {
|
||||||
|
String authorizationKey = "lkl_tk_authorization";
|
||||||
|
Object lklTkToken = redisService.get(authorizationKey);
|
||||||
|
if (ObjectUtil.isNotEmpty(lklTkToken)) {
|
||||||
|
return lklTkToken.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> formData = new HashMap<>();
|
||||||
|
formData.put("grant_type", "client_credentials");
|
||||||
|
formData.put("client_id", clientId);
|
||||||
|
formData.put("client_secret", clientSecret);
|
||||||
|
|
||||||
|
String response = RestTemplateHttpUtil.sendPostFormData(buildLklTkUrl("/oauth/token"), null, formData, String.class);
|
||||||
|
if (ObjectUtil.isEmpty(response)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject jsonObj = JSONUtil.parseObj(response);
|
||||||
|
if (jsonObj == null || StrUtil.isBlank(jsonObj.getStr("access_token"))) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String token = jsonObj.getStr("token_type") + jsonObj.getStr("access_token");
|
||||||
|
redisService.set(authorizationKey, token, jsonObj.getLong("expires_in"));
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -445,7 +445,7 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
|
|||||||
|
|
||||||
AccountUserBase accountUserBase2 = accountService.saveOrUpdateUserBase2(accountUserBase);
|
AccountUserBase accountUserBase2 = accountService.saveOrUpdateUserBase2(accountUserBase);
|
||||||
|
|
||||||
// 新增用户记录后,不知道有没有返回 userId ?
|
// 新增用户记录后,返回 userId ?
|
||||||
Integer userId = accountUserBase2.getUser_id();
|
Integer userId = accountUserBase2.getUser_id();
|
||||||
if (userId == null || userId <= 0) {
|
if (userId == null || userId <= 0) {
|
||||||
continue;
|
continue;
|
||||||
@ -466,7 +466,7 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
|
|||||||
boolean success = accountService.saveOrUpdateUserInfo(accountUserInfo);
|
boolean success = accountService.saveOrUpdateUserInfo(accountUserInfo);
|
||||||
|
|
||||||
if (member.getUser_money() != null || member.getUser_points() != null) {
|
if (member.getUser_money() != null || member.getUser_points() != null) {
|
||||||
// 用户支付资源,积分,余额
|
// pay_user_resource 用户支付资源,积分,余额
|
||||||
PayUserResource payUserResource = new PayUserResource();
|
PayUserResource payUserResource = new PayUserResource();
|
||||||
payUserResource.setUser_id(userId);
|
payUserResource.setUser_id(userId);
|
||||||
payUserResource.setUser_money(member.getUser_money());
|
payUserResource.setUser_money(member.getUser_money());
|
||||||
|
|||||||
@ -136,4 +136,13 @@ sf-express:
|
|||||||
appid: 1711573316
|
appid: 1711573316
|
||||||
appkey: cd57608baa9c00fe1cda5f652b14240d
|
appkey: cd57608baa9c00fe1cda5f652b14240d
|
||||||
dev_id: 1711573316
|
dev_id: 1711573316
|
||||||
enable: 2
|
enable: 2
|
||||||
|
#拉卡拉进件配置
|
||||||
|
lakala:
|
||||||
|
tk:
|
||||||
|
#服务地址
|
||||||
|
server_url: https://test.wsmsd.cn/sit/htkauth
|
||||||
|
client_id: lsycs
|
||||||
|
client_secret: XPa1HB5d55Ig0qV8
|
||||||
|
api_pub_key_path: payKey/lakala/dev/tk_api_public_key.txt
|
||||||
|
api_pri_key_path: payKey/lakala/dev/tk_api_private_key.txt
|
||||||
Loading…
Reference in New Issue
Block a user