main
parent
f848bf9e2a
commit
2b14390c27
|
|
@ -1,8 +1,12 @@
|
||||||
package com.ruoyi.app.controller;
|
package com.ruoyi.app.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.app.domain.AppRegister;
|
import com.ruoyi.app.domain.AppRegister;
|
||||||
import com.ruoyi.app.domain.AppUser;
|
import com.ruoyi.app.domain.AppUser;
|
||||||
|
import com.ruoyi.app.domain.dto.HelperUtil;
|
||||||
|
import com.ruoyi.app.domain.dto.PayConfig;
|
||||||
import com.ruoyi.app.domain.vo.AppUserVo;
|
import com.ruoyi.app.domain.vo.AppUserVo;
|
||||||
import com.ruoyi.app.form.AppLoginUser;
|
import com.ruoyi.app.form.AppLoginUser;
|
||||||
import com.ruoyi.app.form.LoginForm;
|
import com.ruoyi.app.form.LoginForm;
|
||||||
|
|
@ -13,6 +17,7 @@ import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.utils.ip.IpUtils;
|
import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||||
import com.ruoyi.common.core.utils.uuid.IdUtils;
|
import com.ruoyi.common.core.utils.uuid.IdUtils;
|
||||||
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
import com.ruoyi.common.redis.service.RedisService;
|
import com.ruoyi.common.redis.service.RedisService;
|
||||||
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.common.security.service.TokenService;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
import com.ruoyi.system.api.model.LoginUser;
|
||||||
|
|
@ -23,6 +28,8 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.common.Constants.ACCESS_TOKEN;
|
import static com.alibaba.nacos.api.common.Constants.ACCESS_TOKEN;
|
||||||
|
|
@ -130,6 +137,23 @@ public class AppLoginController {
|
||||||
return R.ok(appUserVo);
|
return R.ok(appUserVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/getAccessToken")
|
||||||
|
@ApiOperation(value = "微信token" , notes = "微信token")
|
||||||
|
public AjaxResult getAccessToken(@RequestParam String code) {
|
||||||
|
Map<String ,String > map = new HashMap<>();
|
||||||
|
map.put("appid", PayConfig.APPID);
|
||||||
|
map.put("secret", PayConfig.appSecret);
|
||||||
|
map.put("code",code);
|
||||||
|
map.put("grant_type","authorization_code");
|
||||||
|
try {
|
||||||
|
String resultStr = HelperUtil.sendHttpGet(PayConfig.access_token, map);
|
||||||
|
JSONObject json = JSON.parseObject(resultStr,JSONObject.class);
|
||||||
|
return AjaxResult.success(json);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return AjaxResult.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.app.controller;
|
package com.ruoyi.app.controller;
|
||||||
|
|
||||||
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.AlipayApiException;
|
||||||
|
import com.alipay.api.internal.util.AlipaySignature;
|
||||||
import com.alipay.api.request.AlipayTradeCreateRequest;
|
import com.alipay.api.request.AlipayTradeCreateRequest;
|
||||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||||
import com.ruoyi.app.domain.*;
|
import com.ruoyi.app.domain.*;
|
||||||
|
|
@ -32,6 +33,7 @@ import org.dom4j.Document;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -41,6 +43,8 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.alipay.api.AlipayConstants.CHARSET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态评论Controller
|
* 动态评论Controller
|
||||||
*
|
*
|
||||||
|
|
@ -206,7 +210,6 @@ public class PayController extends BaseController
|
||||||
public AjaxResult wechatPrePay(@RequestBody AppOrderArg appOrderArg) {
|
public AjaxResult wechatPrePay(@RequestBody AppOrderArg appOrderArg) {
|
||||||
Integer price = Integer.valueOf(appOrderArg.getPrice());
|
Integer price = Integer.valueOf(appOrderArg.getPrice());
|
||||||
|
|
||||||
PayConfig payConfig = getPayConfigByAppid();
|
|
||||||
String orderNo = KeyUtil.generateUniqueKey();
|
String orderNo = KeyUtil.generateUniqueKey();
|
||||||
|
|
||||||
WeChatPrepayResult prePayResult = new WeChatPrepayResult();
|
WeChatPrepayResult prePayResult = new WeChatPrepayResult();
|
||||||
|
|
@ -217,7 +220,7 @@ public class PayController extends BaseController
|
||||||
System.out.println("orderNo:" + orderNo);
|
System.out.println("orderNo:" + orderNo);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prePayId = payService.getPrepayId(orderNo, price, nonce_str, timeStamp,payConfig);
|
prePayId = payService.getPrepayId(orderNo, price, nonce_str, timeStamp);
|
||||||
log.info("=========prepayid===>>"+prePayId);
|
log.info("=========prepayid===>>"+prePayId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("==========prepayRequest===>>>error");
|
log.info("==========prepayRequest===>>>error");
|
||||||
|
|
@ -228,12 +231,12 @@ public class PayController extends BaseController
|
||||||
return AjaxResult.error("支付失败");
|
return AjaxResult.error("支付失败");
|
||||||
}
|
}
|
||||||
SortedMap<String, Object> ps = new TreeMap<String, Object>();
|
SortedMap<String, Object> ps = new TreeMap<String, Object>();
|
||||||
ps.put("appId", payConfig.getAPPID());//app_id
|
ps.put("appId", PayConfig.APPID);//app_id
|
||||||
ps.put("timeStamp",timeStamp);//北京时间时间戳
|
ps.put("timeStamp",timeStamp);//北京时间时间戳
|
||||||
ps.put("nonceStr", nonce_str);//自定义不重复的长度不长于32位
|
ps.put("nonceStr", nonce_str);//自定义不重复的长度不长于32位
|
||||||
ps.put("package", "prepay_id="+prePayId);
|
ps.put("package", "prepay_id="+prePayId);
|
||||||
ps.put("signType", "MD5");
|
ps.put("signType", "MD5");
|
||||||
String paySign = PayUtils.createSign(payConfig.getAPP_KEY(), ps);
|
String paySign = PayUtils.createSign(PayConfig.APP_KEY, ps);
|
||||||
if (paySign==null || "".equals(paySign)) {
|
if (paySign==null || "".equals(paySign)) {
|
||||||
prePayResult.setCode("002");
|
prePayResult.setCode("002");
|
||||||
return AjaxResult.error("支付失败");
|
return AjaxResult.error("支付失败");
|
||||||
|
|
@ -242,11 +245,11 @@ public class PayController extends BaseController
|
||||||
AppOrder order = new AppOrder();
|
AppOrder order = new AppOrder();
|
||||||
order.setOutTradeNo(orderNo);
|
order.setOutTradeNo(orderNo);
|
||||||
order.setPrice(appOrderArg.getPrice());
|
order.setPrice(appOrderArg.getPrice());
|
||||||
order.setAppId(payConfig.getAPPID());
|
order.setAppId(PayConfig.APPID);
|
||||||
order.setUserId(appOrderArg.getUserId());
|
order.setUserId(appOrderArg.getUserId());
|
||||||
order.setPayStatus(1);
|
order.setPayStatus(1);
|
||||||
order.setPaySoure(1);
|
order.setPaySoure(1);
|
||||||
order.setMchId(payConfig.MCH_ID);
|
order.setMchId(PayConfig.MCH_ID);
|
||||||
order.setCreateTime(new Date());
|
order.setCreateTime(new Date());
|
||||||
order.setLevel(appOrderArg.getLevel());
|
order.setLevel(appOrderArg.getLevel());
|
||||||
appOrderMapper.insertAppOrder(order);
|
appOrderMapper.insertAppOrder(order);
|
||||||
|
|
@ -318,10 +321,11 @@ public class PayController extends BaseController
|
||||||
log.info("========>PrintWriter fail");
|
log.info("========>PrintWriter fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Value("${config.alipay.publicKey}")
|
||||||
|
private static String ALIPAY_PUBLIC_KEY;
|
||||||
@RequestMapping(value = "/aliPayCallback")
|
@RequestMapping(value = "/aliPayCallback")
|
||||||
public void aliPayCallback(HttpServletRequest request, HttpServletResponse response) {
|
public void aliPayCallback(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
||||||
/*log.info("=======>>>开始获取支付宝支付返回信息");
|
log.info("=======>>>开始获取支付宝支付返回信息");
|
||||||
//获取支付宝POST过来反馈信息,将异步通知中收到的待验证所有参数都存放到map中
|
//获取支付宝POST过来反馈信息,将异步通知中收到的待验证所有参数都存放到map中
|
||||||
Map< String , String > params = new HashMap < String , String > ();
|
Map< String , String > params = new HashMap < String , String > ();
|
||||||
Map requestParams = request.getParameterMap();
|
Map requestParams = request.getParameterMap();
|
||||||
|
|
@ -338,17 +342,24 @@ public class PayController extends BaseController
|
||||||
}
|
}
|
||||||
//调用SDK验证签名
|
//调用SDK验证签名
|
||||||
//公钥验签示例代码
|
//公钥验签示例代码
|
||||||
boolean signVerified = AlipaySignature.rsaCheckV1(params, ALIPAY_PUBLIC_KEY, CHARSET,sign_type) ;
|
boolean signVerified = AlipaySignature.rsaCheckV1(params, ALIPAY_PUBLIC_KEY, "UTF-8","RSA2") ;
|
||||||
//公钥证书验签示例代码
|
//公钥证书验签示例代码
|
||||||
// boolean flag = AlipaySignature.rsaCertCheckV1(params,alipayPublicCertPath,"UTF-8","RSA2");
|
// boolean flag = AlipaySignature.rsaCertCheckV1(params,alipayPublicCertPath,"UTF-8","RSA2");
|
||||||
|
|
||||||
if (signVerified){
|
if (signVerified){
|
||||||
// TODO 验签成功后
|
// TODO 验签成功后
|
||||||
//按照支付结果异步通知中的描述,对支付结果中的业务内容进行1\2\3\4二次校验,校验成功后在response中返回success
|
//按照支付结果异步通知中的描述,对支付结果中的业务内容进行1\2\3\4二次校验,校验成功后在response中返回success
|
||||||
} else {
|
} else {
|
||||||
// TODO 验签失败则记录异常日志,并在response中返回fail.
|
// TODO 验签失败则记录异常日志,并在response中返回fail.
|
||||||
}*/
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
PrintWriter out;
|
||||||
|
try {
|
||||||
|
out = response.getWriter();
|
||||||
|
out.println("success");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
/*StringBuilder sb = new StringBuilder();
|
||||||
InputStream in;
|
InputStream in;
|
||||||
try {
|
try {
|
||||||
in = request.getInputStream();
|
in = request.getInputStream();
|
||||||
|
|
@ -399,7 +410,7 @@ public class PayController extends BaseController
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("异常订单:" + wexinResult.toString());
|
log.info("异常订单:" + wexinResult.toString());
|
||||||
log.info("========>PrintWriter fail");
|
log.info("========>PrintWriter fail");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -488,15 +499,4 @@ public class PayController extends BaseController
|
||||||
return AjaxResult.error(result.getMsg());
|
return AjaxResult.error(result.getMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PayConfig getPayConfigByAppid() {
|
|
||||||
PayConfig payConfig = new PayConfig();
|
|
||||||
payConfig.setAPPID(payConfig.getAPPID());
|
|
||||||
payConfig.setMCH_ID(payConfig.getMCH_ID());
|
|
||||||
payConfig.setWechat_notify_url(payConfig.getWechat_notify_url());
|
|
||||||
payConfig.setBody(payConfig.body);
|
|
||||||
payConfig.setAPP_KEY(payConfig.getAPP_KEY());
|
|
||||||
payConfig.setPayUrl(payConfig.payUrl);
|
|
||||||
return payConfig;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,41 @@
|
||||||
package com.ruoyi.app.domain.dto;
|
package com.ruoyi.app.domain.dto;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
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.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HelperUtil {
|
public class HelperUtil {
|
||||||
|
|
||||||
|
|
||||||
|
// utf-8字符编码
|
||||||
|
public static final String CHARSET_UTF_8 = "utf-8";
|
||||||
|
|
||||||
|
// 连接管理器
|
||||||
|
private static PoolingHttpClientConnectionManager pool;
|
||||||
|
|
||||||
|
// 请求配置
|
||||||
|
private static RequestConfig requestConfig;
|
||||||
|
|
||||||
enum RequestMethod {
|
enum RequestMethod {
|
||||||
POST, GET, PUT
|
POST, GET, PUT
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +46,98 @@ public class HelperUtil {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送 get请求
|
||||||
|
*
|
||||||
|
* @param httpUrl
|
||||||
|
*/
|
||||||
|
public static String sendHttpGet(String httpUrl, Map<String, String> parameters) {
|
||||||
|
if (!CollectionUtils.isEmpty(parameters)) {
|
||||||
|
String paramString = "?";
|
||||||
|
for (String para : parameters.keySet()) {
|
||||||
|
if ("?".equals(paramString)) {
|
||||||
|
paramString = paramString + para + "=" + parameters.get(para);
|
||||||
|
} else {
|
||||||
|
paramString = paramString + "&" + para + "=" + parameters.get(para);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
httpUrl = httpUrl + paramString;
|
||||||
|
}
|
||||||
|
return sendHttpGet(httpUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送Get请求
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String sendHttpGet(String httpUrl) {
|
||||||
|
HttpGet httpGet = new HttpGet(httpUrl);
|
||||||
|
|
||||||
|
CloseableHttpClient httpClient = null;
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
// 响应内容
|
||||||
|
String responseContent = null;
|
||||||
|
try {
|
||||||
|
// 创建默认的httpClient实例.
|
||||||
|
httpClient = getHttpClient();
|
||||||
|
// 配置请求信息
|
||||||
|
httpGet.setConfig(requestConfig);
|
||||||
|
// 执行请求
|
||||||
|
response = httpClient.execute(httpGet);
|
||||||
|
// 得到响应实例
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
|
// 可以获得响应头
|
||||||
|
// Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE);
|
||||||
|
// for (Header header : headers) {
|
||||||
|
// System.out.println(header.getName());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 得到响应类型
|
||||||
|
// System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType());
|
||||||
|
|
||||||
|
// 判断响应状态
|
||||||
|
if (response.getStatusLine().getStatusCode() >= 300) {
|
||||||
|
throw new Exception(
|
||||||
|
"HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
|
||||||
|
responseContent = EntityUtils.toString(entity, CHARSET_UTF_8);
|
||||||
|
EntityUtils.consume(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
// 释放资源
|
||||||
|
if (response != null) {
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CloseableHttpClient getHttpClient() {
|
||||||
|
|
||||||
|
CloseableHttpClient httpClient = HttpClients.custom()
|
||||||
|
// 设置连接池管理
|
||||||
|
.setConnectionManager(pool)
|
||||||
|
// 设置请求配置
|
||||||
|
.setDefaultRequestConfig(requestConfig)
|
||||||
|
// 设置重试次数
|
||||||
|
.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 取得服务端返回数据
|
// 取得服务端返回数据
|
||||||
private static String getServerResponse(String url, String body, RequestMethod method) {
|
private static String getServerResponse(String url, String body, RequestMethod method) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,19 @@ import lombok.ToString;
|
||||||
public class PayConfig {
|
public class PayConfig {
|
||||||
|
|
||||||
//商户APPID
|
//商户APPID
|
||||||
public String APPID = "wx55ff808ba0e28b1d";
|
public static String APPID = "wx55ff808ba0e28b1d";
|
||||||
|
public static String appSecret= "78481b6b0718c5c5fc7dcb962e18b799";
|
||||||
//商户账户
|
//商户账户
|
||||||
public String MCH_ID = "1646646755";
|
public static String MCH_ID = "1646646755";
|
||||||
//异步回调地址
|
//异步回调地址
|
||||||
public String wechat_notify_url = "127.0.0.1";
|
public static String wechat_notify_url = "127.0.0.1";
|
||||||
//商品描述
|
//商品描述
|
||||||
public String body = "会员充值";
|
public static String body = "会员充值";
|
||||||
|
|
||||||
public String APP_KEY = "Zzvi53pvCLUdFtvQ3EB0QLHQeKTctZ1c";
|
public static String APP_KEY = "Zzvi53pvCLUdFtvQ3EB0QLHQeKTctZ1c";
|
||||||
|
|
||||||
|
public static String payUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";//下单
|
||||||
|
|
||||||
|
public static String access_token = "https://api.weixin.qq.com/sns/oauth2/access_token";
|
||||||
|
|
||||||
public String payUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";//下单
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import com.alipay.api.internal.util.AlipaySignature;
|
||||||
import com.alipay.api.request.AlipayTradeCreateRequest;
|
import com.alipay.api.request.AlipayTradeCreateRequest;
|
||||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||||
|
import com.ruoyi.app.domain.dto.KeyUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -17,13 +19,16 @@ import java.util.Map;
|
||||||
public class AlipayService {
|
public class AlipayService {
|
||||||
|
|
||||||
// 支付宝网关
|
// 支付宝网关
|
||||||
private static final String ALIPAY_GATEWAY = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
|
// private static final String ALIPAY_GATEWAY = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
|
||||||
|
private static final String ALIPAY_GATEWAY = "https://openapi.alipay.com/gateway.do";
|
||||||
// 应用ID
|
// 应用ID
|
||||||
public static final String APP_ID = "9021000136647545";
|
public static final String APP_ID = "2021004144677656";
|
||||||
// 私钥pkcs8格式
|
// 私钥pkcs8格式
|
||||||
private static final String APP_PRIVATE_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQChzpB6JWlP/2ZWtxcjvphN/ePSCkWYe1hSRwOyy+3jTvA31aVuPOOgC0WludwqLnWJnn6JV5m+Q7ZyJ4sOWmU4f+dDs2F31zrb21QLmF9ZcNpveVTsPQFYCZER2VU8ckLkIqS4RSKySJFGzbmuYyu+nIOct6dUoEhpEa+8o6k9cykplmoXI2wCn24c87qGLkKsvZQrT2nWI46ua57AvBAbkEGkFIbS4FxggP6Z1rUbj3tAREpEO7VQFvfe/DISIzer91U+yEnlmcz9nPhxmaIc0o8xbTW2surSMfoIzXkV8xit9EclGXkb4fZPr8t4N/viEVigQPGw9vxoDrKLhUphAgMBAAECggEAPnd1tYI97wFlq/KRP150hB+RVWRby+tKhLEfz2YFV+0Atj2H2VAufHn9kGZ5hdtbyx5iMXmdRCP2CooTmB3z1+UhDjTxWwe/lGNPRg60ON5lpgWMcIt4ulkvJVnnGyfthQ+O0gj2xSdY1qHTnmxw1eysrtMECZq7eby3QLdaPftYm/g57mHAjruUZBvylEBCnEpY94y7qyYUtgdefDB9n0NIVpqkUjIqOZutZsCjxkFEQlKerPJPllCzuzPQS3YHxTBLdu89F2JGHeMwO17f7XzA7OS3Jf6OvbyQ1OuoAF+NWnojzrehwhh4fqcg5I3rm/opZzgFvb4KxK6mc4sVwQKBgQD2C32Iv1RgCKVAURwKWogIZSkScs8Am2WIP/iCK4sX1+rRbCFlc6TaTqO3hSyR1CeSWwpdB/6TqfMCklCj0pLCiATzbWfSCQoDq6LxfHvs2o/ilu8T/qV5qI5CnugIzSni/3NfBEz2vwjHS8PAGyHrvedTay9SjEeFaDIzTm7eOQKBgQCoWot6zzJEKGXn5y2s828yQBU82OnE+OAf8sjT4MY5lF65+JmbARaIMY40OejA/fUngC/4bi6oNExEv5Y94w+E8VryZOm4lMzDevuImJWQoJsFoHS4rMtAaQly8GRpk18flVB9B1ZLM345sujcnFjPnmJInvDuI2cQaf8rsN1NaQKBgBWTbl+2f3yoZW1db3sM807hKBfhD3v7JI0tJuqrTNg7a/EPbWJLINKwALVQLVdgZlP0PdVopQ9n4NKB6CZlic8bRGvgVTFa75Dg1Tod83QSunlhSPfU5cfkWw1GiAx1iU3JnuFfLCybFfb8Et9ewbu9fHKZPJ4dhQwS1gwfvaMpAoGARE1/+1JmxWpSdfS//kRBn/SJ6UbkCSsj2zJoMjYmliPRDsiCoXWei6D3Xc8E1I/0T5NdYwBo44tcSiQks3UUzc4SJPe2L1IHhWO2+2NUgvn2CyFfWbGZQMecsso/IupMlIbCwgchBp+cnZItkZvJGGrc2zPI8gThArLOeQ5nqskCgYAxkVuRjkrY3Ide2bl17MD/qUZGUrXgfZJxOFI0ya+QinnGrPAxQaWZqyatp663DHOnMjD68Me8t/czhgMLm5g7VcxxPp60Qsx/9F/7l80LacFhMCrhCFW6GNSN1oFyAxokBBe+NgqDJIMJMk3zD4C5SvT1yc19TxoxEwa8lqgLLw==";
|
@Value("${config.alipay.privateKey}")
|
||||||
|
private static String APP_PRIVATE_KEY;
|
||||||
// 支付宝公钥
|
// 支付宝公钥
|
||||||
private static final String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyCpeqEUH58ZlTyGvHMD5/L46XVMJAWz5hRdp7oc5KRVt+7IhrNsqLwqRIp5jDXP8HjdnBOkuGb8FvnKSXwN4ydbR0PXXKIm1HSclJH2A3qjeYDuO1QJiE6UU/eB69sdTEfbnMqAaCPsFAbnCgvRZ+zowpVPqfZOs83812O8j+8UC8rEDyCtot26wLiz71Ccs5WzxQBVK02m258L5R43yb4NP9pXF8KZFg9vNpqTVHtX3p/PuMng6NSCbw2praghj8VFT849VPT0uGYRAEbx9uY3R+Y/GJtDlk4oYtMcA+56puudqGvPP96JhHYI5fr5M6IKewZTthG15P2li9dUCwwIDAQAB";
|
@Value("${config.alipay.publicKey}")
|
||||||
|
private static String ALIPAY_PUBLIC_KEY;
|
||||||
// 格式化
|
// 格式化
|
||||||
private static final String FORMAT = "json";
|
private static final String FORMAT = "json";
|
||||||
// 字符编码
|
// 字符编码
|
||||||
|
|
@ -61,6 +66,13 @@ public class AlipayService {
|
||||||
return alipayClient.sdkExecute(alipayRequest);
|
return alipayClient.sdkExecute(alipayRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception{
|
||||||
|
AlipayService alipayService = new AlipayService();
|
||||||
|
String orderNo = KeyUtil.generateUniqueKey();
|
||||||
|
AlipayTradeCreateResponse result = alipayService.startPay(orderNo, "1.00");
|
||||||
|
System.out.println(result.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
// https://api.xx.com/receive_notify.htm?gmt_payment=2015-06-11 22:33:59¬ify_id=42af7baacd1d3746cf7b56752b91edcj34&seller_email=testyufabu07@alipay.com¬ify_type=trade_status_sync&sign=kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=&trade_no=2015061121001004400068549373&out_trade_no=21repl2ac2eOutTradeNo322&gmt_create=2015-06-11 22:33:46&seller_id=2088211521646673¬ify_time=2015-06-11 22:34:03&subject=FACE_TO_FACE_PAYMENT_PRECREATE中文&trade_status=TRADE_SUCCESS&sign_type=RSA2
|
// https://api.xx.com/receive_notify.htm?gmt_payment=2015-06-11 22:33:59¬ify_id=42af7baacd1d3746cf7b56752b91edcj34&seller_email=testyufabu07@alipay.com¬ify_type=trade_status_sync&sign=kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=&trade_no=2015061121001004400068549373&out_trade_no=21repl2ac2eOutTradeNo322&gmt_create=2015-06-11 22:33:46&seller_id=2088211521646673¬ify_time=2015-06-11 22:34:03&subject=FACE_TO_FACE_PAYMENT_PRECREATE中文&trade_status=TRADE_SUCCESS&sign_type=RSA2
|
||||||
public void handleCallback(HttpServletRequest request) {
|
public void handleCallback(HttpServletRequest request) {
|
||||||
// 获取支付宝POST过来的数据
|
// 获取支付宝POST过来的数据
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public interface IPayService {
|
||||||
* @param timeStamp
|
* @param timeStamp
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getPrepayId(String orderId, int orderMoney, String nonce_str, long timeStamp, PayConfig weChatConfig);
|
String getPrepayId(String orderId, int orderMoney, String nonce_str, long timeStamp);
|
||||||
/**
|
/**
|
||||||
* 查询微信支付
|
* 查询微信支付
|
||||||
* @param oid
|
* @param oid
|
||||||
|
|
|
||||||
|
|
@ -23,28 +23,28 @@ public class PayServiceImpl implements IPayService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrepayId(String orderId, int orderMoney, String nonce_str, long timeStamp, PayConfig weChatConfig) {
|
public String getPrepayId(String orderId, int orderMoney, String nonce_str, long timeStamp) {
|
||||||
//long fee = (long) (orderMoney * 100); // 转换为分
|
//long fee = (long) (orderMoney * 100); // 转换为分
|
||||||
SortedMap<String, Object> parameterMap = new TreeMap<String, Object>();
|
SortedMap<String, Object> parameterMap = new TreeMap<String, Object>();
|
||||||
parameterMap.put("appid", weChatConfig.getAPPID());
|
parameterMap.put("appid", PayConfig.APPID);
|
||||||
parameterMap.put("mch_id", weChatConfig.getMCH_ID());
|
parameterMap.put("mch_id", PayConfig.MCH_ID);
|
||||||
parameterMap.put("nonce_str", nonce_str);
|
parameterMap.put("nonce_str", nonce_str);
|
||||||
parameterMap.put("body", weChatConfig.getBody());
|
parameterMap.put("body", PayConfig.body);
|
||||||
parameterMap.put("out_trade_no", orderId);
|
parameterMap.put("out_trade_no", orderId);
|
||||||
parameterMap.put("total_fee", orderMoney);
|
parameterMap.put("total_fee", orderMoney);
|
||||||
parameterMap.put("spbill_create_ip","127.0.0.1");
|
parameterMap.put("spbill_create_ip","127.0.0.1");
|
||||||
parameterMap.put("notify_url", weChatConfig.getWechat_notify_url());
|
parameterMap.put("notify_url", PayConfig.wechat_notify_url);
|
||||||
parameterMap.put("trade_type", "JSAPI");
|
parameterMap.put("trade_type", "JSAPI");
|
||||||
//parameterMap.put("trade_type", "APP");
|
//parameterMap.put("trade_type", "APP");
|
||||||
//parameterMap.put("trade_type", "MWEB");
|
//parameterMap.put("trade_type", "MWEB");
|
||||||
//parameterMap.put("openid", openId);
|
//parameterMap.put("openid", openId);
|
||||||
String sign = PayUtils.createSign(weChatConfig.getAPP_KEY(), parameterMap);
|
String sign = PayUtils.createSign(PayConfig.wechat_notify_url, parameterMap);
|
||||||
log.info("sign:" + sign);
|
log.info("sign:" + sign);
|
||||||
parameterMap.put("sign", sign);
|
parameterMap.put("sign", sign);
|
||||||
String body = PayUtils.getRequestXml(parameterMap);
|
String body = PayUtils.getRequestXml(parameterMap);
|
||||||
String response = "";
|
String response = "";
|
||||||
try {
|
try {
|
||||||
response = HelperUtil.post(weChatConfig.payUrl, body);
|
response = HelperUtil.post(PayConfig.payUrl, body);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info(e.getMessage());
|
log.info(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,3 +25,8 @@ spring:
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
config:
|
||||||
|
alipay:
|
||||||
|
publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyCpeqEUH58ZlTyGvHMD5/L46XVMJAWz5hRdp7oc5KRVt+7IhrNsqLwqRIp5jDXP8HjdnBOkuGb8FvnKSXwN4ydbR0PXXKIm1HSclJH2A3qjeYDuO1QJiE6UU/eB69sdTEfbnMqAaCPsFAbnCgvRZ+zowpVPqfZOs83812O8j+8UC8rEDyCtot26wLiz71Ccs5WzxQBVK02m258L5R43yb4NP9pXF8KZFg9vNpqTVHtX3p/PuMng6NSCbw2praghj8VFT849VPT0uGYRAEbx9uY3R+Y/GJtDlk4oYtMcA+56puudqGvPP96JhHYI5fr5M6IKewZTthG15P2li9dUCwwIDAQAB
|
||||||
|
privateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCavGqUrH2Q37jLzEvQzUizyTT6DPJ+8CoBvGYASjkDGfLyXtMSQKaWdhRi/RdNzd/7PT4+I/0Q96B4n+ykUiApygNqW02AmSilClPtski5nl+ur/BBdJq8aUaoj+/DBneiVqyYge8eagEcfp1m1Ou8BLeFZUoOVzLcO0aysw7aTpA3LPwda0VkQghfYsCvajLYR35F7kEE0Fo8AUzgDZCZn3QI4x72QTpBlZxte0xpx8uLYUFfItm1uhcX2cmXfH86JzLJuKy1lOV6xuu5zh6i8Ba0nEn47L1wuYYBJUREWl7cc1/QnEyWToNdbYF7Lm3EWDM7JUYDHkt/T6Q1lZBHAgMBAAECggEAAOnp6zTVjPx1N+bd7762ljEy+eMHr441gUsegxPtIEKP97RtpKbzFOJfnnIGKDR2BSLIck9+GBKORQgUuqetfvGtcXxWidLdtZPJCRdLbKUtxXdOgORyYXhxrV8kOE+adz/xxvjFc7WGiieJQGkzdynD96qwdEM5jqle8oEyLkHUIY21wFsAChp0mJpdlV6C214FeahgRhEWVcPVz0LcyVKzChWrCnKFp6kmaAr1HQK/i9e1zI/6kr2BYdkp1hCQq6X3LKj8KHLZ2HtbPHjTDzStpXdocsuSi/C1+17oWAYDNy3KFNPLhhwi59MHow9elMTfyTdH1msWKVsHJtcWoQKBgQDnfNDq757DE9Ztjt1zAhY9Byqo4AYiZrL34xE4Sw47f3RUo1pmiaROuWwAdnzmbP7SRaURRRCbj0PO4Rtd4PlOW7IvkzGJ+M6HjiqrTzaO93LFUrdCpJ9k6lr15xko1dr77coAN57GfSwWy/H8Vdcx0iJNcI85EG+ELrEDrUIJUQKBgQCrHwM5fK56+B0V0IvLiYtgZgfFEqf/5VFgde5glzLl2QUtblO3r7amnXWjHR61Y2iwHeAlVmoh5EKaqs6BZDid4AVWJeKK96RvkIdFKRBDk9ldMZG8cg5G/Jt45TNTCwl7R/XvZXmnPGstwH3cZ3yD9TeD1Hbsu9QZtbQe90yaFwKBgQCu1cyMxLIqMF9xm8eRx2+4ZCNKLPk1Hk/pfWxSEg4LzfW0vzPV4fthIhZ6OwOWnZfQhJ1pb7pdY1UZeVdMDlD9Z7Aq0odF589E/pEnlcplLGtYsWKMSP3CIGbW9tY/y1V7lVtN0rRuwbd8+EgqB0Ni84zI5EyoEsvHD+TOHBuWIQKBgQCmiJP2ymRzwCtuI3spJj7CHgnJvRJKc73yhlLrJbqe/cmQISLQTO0Q0YS+rYRJOumTHEAbljHLsf0v0LMQMZz36CDJai1C2SbqfFlo8UGmwqhzjd4q60UByKz1xvlgBAnCNJIf3T27h403BXJ3oS8IrQjN/2ONmG4eZztYN4wRGQKBgGfKV3dU1MKAAN1xkqmeAhCmEk73oGIRe580I3TvSnNXJVooo/F7GLARxMZkBpGjpDh7mtfqwkk3hrLD3VGd+JzdVlEbZpGbLlukk5OPJ/iT1RbTNqWfFx/TUpohtc2yFiYeQcxmOP/XkqK2zgosepk//wRSLvyvg3+hcTglHokW";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<include refid="appUserColumns"/>,
|
<include refid="appUserColumns"/>,
|
||||||
s.name as "schoolName",
|
s.name as "schoolName",
|
||||||
t.name as "cityName",
|
t.name as "cityName",
|
||||||
|
a.id as "userId",
|
||||||
count(DISTINCT(r.id)) as "friendNum",
|
count(DISTINCT(r.id)) as "friendNum",
|
||||||
count(DISTINCT(l.id)) as "likeNum",
|
count(DISTINCT(l.id)) as "likeNum",
|
||||||
count(DISTINCT(f.id)) as "attentionNum",
|
count(DISTINCT(f.id)) as "attentionNum",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue