parent
9aac81d0e5
commit
02373d1178
@ -0,0 +1,80 @@ |
||||
package com.hfkj.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest; |
||||
import com.alipay.api.request.AlipayUserInfoShareRequest; |
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse; |
||||
import com.alipay.api.response.AlipayUserInfoShareResponse; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.alipay.AlipayUtils; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.entity.BsUserParentRel; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.user.BsUserGradeService; |
||||
import com.hfkj.service.user.BsUserParentRelService; |
||||
import com.hfkj.service.user.BsUserPlatformAuthorizeService; |
||||
import com.hfkj.service.user.BsUserService; |
||||
import com.hfkj.sysenum.user.UserGradeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* @className: CmsController |
||||
* @author: HuRui |
||||
* @date: 2024/9/24 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/userAuth") |
||||
@Api(value = "用户管理") |
||||
public class BsUserAuthController { |
||||
private static Logger log = LoggerFactory.getLogger(BsUserAuthController.class); |
||||
@Resource |
||||
private BsUserService userService; |
||||
@Resource |
||||
private BsUserGradeService userGradeService; |
||||
@Resource |
||||
private BsUserParentRelService userParentRelService; |
||||
@Resource |
||||
private BsUserPlatformAuthorizeService userPlatformAuthorizeService; |
||||
|
||||
@RequestMapping(value="/alipay",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "支付宝授权") |
||||
public ResponseData alipay(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || StringUtils.isBlank(body.getString("code"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
}/* |
||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); |
||||
request.setGrantType("authorization_code"); |
||||
request.setCode(body.getString("code")); |
||||
AlipaySystemOauthTokenResponse response = AlipayUtils.initClient().certificateExecute(request); |
||||
if(response.isSuccess()){ |
||||
return ResponseMsgUtil.success(response); |
||||
}*/ |
||||
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest(); |
||||
AlipayUserInfoShareResponse response = AlipayUtils.initClient().certificateExecute(request,body.getString("code")); |
||||
if(response.isSuccess()){ |
||||
return ResponseMsgUtil.success(response); |
||||
} |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取失败"); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,49 @@ |
||||
package com.hfkj.platform.alipay; |
||||
|
||||
import com.alipay.api.AlipayClient; |
||||
import com.alipay.api.AlipayConfig; |
||||
import com.alipay.api.DefaultAlipayClient; |
||||
|
||||
/** |
||||
* 支付宝配置 |
||||
* @className: AlipayConfig |
||||
* @author: HuRui |
||||
* @date: 2023/2/13 |
||||
**/ |
||||
public class AlipayUtils { |
||||
private final static String serverUrl = "https://openapi.alipay.com/gateway.do"; |
||||
private final static String appId = "2021004149636316"; |
||||
private final static String APP_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCBObA50oioZEmUGTsSPJghAUf/lRT+TC+9HNyu0To3bSkLZ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3wQ0+6GK1GY5nPmsd/2f+otd58LImJdKB5kfNUaJboT9aoqVxDYQnEP4aruIbgDfPbN/tQXes0PGgf9AZT/55zVkwpQKBgFD9kkbctKADuHYrU28fOHAe5rcaZA3yNHncZt5kSPsMJC6kS9xE3FERfJ7ZwWi6Edmi7QwgZwhlN2rFzpgkFl15cQnYNH7izT2kq9GK18+BqRswOyh8nMj3KCpnhfo8vI8mUZehZf196kfRPlaooNVkKQN6nc9J2OU68A9s6JTtAoGBAOTabPjBoxWeNQwF2pR4E5SfXaMBKC7a6/+AMn9oUb9lvTPZtxXkIZkvn5iRz2UmrygLw4UCWKC3T7ujFIO0lHWktzVv2qPbINbfW10p0S/ioFvNxzP+ZDfSFrN03Zoh05H+0NXj1e4REMtIrbx5R+sJn6CVftpYfFcQd/lXy8MR"; |
||||
private final static String APP_CERT_PATH = "/home/project/oil/cert/alipay/appCertPublicKey_2021004149636316.crt"; |
||||
private final static String ALIPAY_CERT_PATH = "/home/project/oil/cert/alipay/alipayCertPublicKey_RSA2.crt"; |
||||
private final static String ALIPAY_ROOT_CERT_PATH = "/home/project/oil/cert/alipay/alipayRootCert.crt"; |
||||
|
||||
/** |
||||
* 初始化客户端请求 |
||||
* @return |
||||
*/ |
||||
public static AlipayClient initClient() throws Exception { |
||||
AlipayConfig alipayConfig = new AlipayConfig(); |
||||
// 设置网关地址
|
||||
alipayConfig.setServerUrl(serverUrl); |
||||
// 设置应用APPID
|
||||
alipayConfig.setAppId(appId); |
||||
// 设置应用私钥
|
||||
alipayConfig.setPrivateKey(APP_PRIVATE_KEY); |
||||
// 设置应用公钥证书路径
|
||||
alipayConfig.setAppCertPath(APP_CERT_PATH); |
||||
// 设置支付宝公钥证书路径
|
||||
alipayConfig.setAlipayPublicCertPath(ALIPAY_CERT_PATH); |
||||
// 设置支付宝根证书路径
|
||||
alipayConfig.setRootCertPath(ALIPAY_ROOT_CERT_PATH); |
||||
// 设置请求格式,固定值json
|
||||
alipayConfig.setFormat("json"); |
||||
// 设置字符集
|
||||
alipayConfig.setCharset("utf-8"); |
||||
// 设置签名类型
|
||||
alipayConfig.setSignType("RSA2"); |
||||
return new DefaultAlipayClient(alipayConfig); |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue