修改请求方式 将feign转为http请求

master
wujingtao 3 years ago
parent 64f4140ad5
commit 8e7d294945

@ -0,0 +1,68 @@
package com.hchbox.api;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hchbox.model.param.CommonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author wujingtao
* @date 2021/10/20
*/
@Component
public class RequestCore {
private final String API_PREFIX = "/source";
@Value("${trade.service.source.url}")
private String url;
/**
*
*
* @param sellerNick
* @param pageable
* @return
*/
public CommonResult<Object> getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable) {
String reqUrl = url + API_PREFIX + "/account/parentAccounts" + "?" + "sellerNick=" + sellerNick + "&pageNumber=" + pageable.getPageNumber() + "&pageSize=" + pageable.getPageSize();
return requestApi(reqUrl);
}
/**
*
*
* @return
*/
public CommonResult<Object> getPayTemplate() {
String reqUrl = url + API_PREFIX + "/pay/template";
return requestApi(reqUrl);
}
/**
*
*
* @param childrenAccountId
* @param payTemplateId
* @return
*/
CommonResult<Object> authorizeChildrenAccount(@RequestParam(value = "childrenAccountId") Long childrenAccountId, @RequestParam(value = "payTemplateId") Long payTemplateId) {
String reqUrl = url + API_PREFIX + "/account/authorize" + "?" + "childrenAccountId=" + childrenAccountId + "&payTemplateId=" + payTemplateId;
return requestApi(reqUrl);
}
private CommonResult<Object> requestApi(String url) {
JSONObject results;
String getResult = HttpUtil
.createGet(url)
.execute()
.charset("utf-8")
.body();
JSONObject o = JSONUtil.parseObj(getResult);
results = o.getJSONObject("data");
return new CommonResult<>().success(results);
}
}

@ -1,7 +1,9 @@
package com.hchbox.module.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.hchbox.api.RequestCore;
import com.hchbox.constant.AuthConstants;
import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.module.entity.SellerAccount;
@ -27,6 +29,8 @@ import org.springframework.web.bind.annotation.*;
public class AccountInfoController {
private final AliPayClient aliPayClient;
private final AccountInfoService accountInfoService;
@Resource
private RequestCore requestCore;
@GetMapping("/list")
@ApiOperation("查询主账号下的子账号")
@ -42,24 +46,24 @@ public class AccountInfoController {
}
@GetMapping("/parent/accounts")
@ApiOperation("查询主账号下的子账号")
public CommonResult<Page<SellerAccount>> getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable) {
return aliPayClient.getParentAccount(sellerNick, pageable);
}
@GetMapping("/pay/template")
@ApiOperation("查询套餐")
public CommonResult<Object> getPayTemplate() {
return aliPayClient.getPayTemplate();
}
@GetMapping("/account/authorize")
@ApiOperation("对子账号授权")
public CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) {
if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) {
return new CommonResult<>().validateFailed("参数错误");
}
return aliPayClient.authorizeChildrenAccount(childrenAccountId, payTemplateId);
@ApiOperation("查询主账号")
public CommonResult<Object> getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable) {
return requestCore.getParentAccount(sellerNick, pageable);
}
//
// @GetMapping("/pay/template")
// @ApiOperation("查询套餐")
// public CommonResult<Object> getPayTemplate() {
// return aliPayClient.getPayTemplate();
// }
//
// @GetMapping("/account/authorize")
// @ApiOperation("对子账号授权")
// public CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) {
// if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) {
// return new CommonResult<>().validateFailed("参数错误");
// }
// return aliPayClient.authorizeChildrenAccount(childrenAccountId, payTemplateId);
// }
}

@ -25,32 +25,4 @@ public interface AliPayClient {
*/
@GetMapping(API_PREFIX + "/account/checkAccount")
Long checkSellAccountByPurchaser(@RequestParam(value = "token") String token);
/**
*
*
* @param sellerNick
* @param pageable
* @return
*/
@GetMapping(API_PREFIX + "/account/parentAccounts")
CommonResult<Page<SellerAccount>> getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable);
/**
*
*
* @return
*/
@GetMapping(API_PREFIX + "/pay/template")
CommonResult<Object> getPayTemplate();
/**
*
*
* @param childrenAccountId
* @param payTemplateId
* @return
*/
@GetMapping("/account/authorize")
CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId);
}

@ -125,6 +125,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
// 放开生成一级分类链接
.antMatchers(HttpMethod.POST, "/api/remoteRecord/createRemoteRecord").permitAll()
.antMatchers(HttpMethod.GET, "/account/parent/accounts").permitAll()
// 自定义匿名访问所有url放行允许匿名和带Token访问细腻化到每个 Request 类型
// GET
.antMatchers(HttpMethod.GET, anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0])).permitAll()

@ -3,6 +3,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:118.178.137.129}:${NACOS_PORT:8848}
# server-addr: ${NACOS_HOST:172.26.244.159}:${NACOS_PORT:8848}
redis:
database: 2
host: 118.178.137.129

@ -55,6 +55,9 @@ jwt:
# 续期时间范围默认1小时单位毫秒
renew: 3600000
trade:
service:
source:
url: http://39.100.226.133:80

@ -87,7 +87,7 @@ public class SellerAccountController {
@GetMapping("/authorize")
@ApiOperation("子账号授权")
public CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) {
public CommonResult<Object> authorizeChildrenAccount(@RequestParam("childrenAccountId")Long childrenAccountId,@RequestParam("payTemplateId") Long payTemplateId) {
if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) {
return new CommonResult<>().validateFailed("参数错误");
}

@ -3,7 +3,7 @@ server:
spring:
profiles:
active: dev
active: prod
servlet:
multipart:
max-file-size: 200MB #单个文件上传大小

@ -342,7 +342,9 @@ public class SellerAccountServiceImpl implements SellerAccountService {
@Override
public CommonResult<Page<SellerAccount>> getParentAccount(String sellerNick, Pageable pageable) {
AccountSearchVo accountSearchVo = new AccountSearchVo();
accountSearchVo.setSellerNick(sellerNick);
if (StrUtil.isNotEmpty(sellerNick)) {
accountSearchVo.setNickname(sellerNick);
}
accountSearchVo.setParentId((long) DefaultNumberConstants.ZERO_NUMBER);
Page<SellerAccount> sellerAccounts = sellerAccountRepository.findAll(
((root, criteriaQuery, cb) ->

@ -12,7 +12,7 @@ import lombok.Data;
public class AccountSearchVo {
@Query(type = Query.Type.INNER_LIKE, propName = "sellerNick")
@ApiModelProperty("sellerNick")
private String sellerNick;
private String nickname;
@Query(type = Query.Type.EQUAL, propName = "parentId")
@ApiModelProperty("parentId")

Loading…
Cancel
Save