Commit 18e64597 authored by liaoanyuan's avatar liaoanyuan

进行支付宝和微信支付与查询次数的串联

parent 4b403421
......@@ -6,6 +6,7 @@ package cn.wisenergy.model.dto;
*/
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
......@@ -18,4 +19,16 @@ public class PayPageDto {
* 支付金额 :金额不能为0
*/
private Integer total;
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", name = "userId")
private Integer userId;
/**
* 支付类型 1:支付宝 2:微信 3:充值卡
*/
@ApiModelProperty(value = "支付类型 1:支付宝 2:微信 3:充值卡", name = "payType")
private Integer payType;
}
......@@ -3,12 +3,15 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.dto.PayPageDto;
import cn.wisenergy.model.dto.PayQueryDto;
import cn.wisenergy.model.vo.AddLimitVo;
import cn.wisenergy.service.app.AliPayService;
import cn.wisenergy.service.app.UserLimitService;
import cn.wisenergy.service.common.Common;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
......@@ -18,6 +21,9 @@ import javax.servlet.http.HttpServletResponse;
@Service
public class AliPayServiceImpl implements AliPayService {
private static final String CHARSET = "UTF-8";
@Autowired
private UserLimitService userLimitService;
@Override
public R<String> doPost(PayPageDto payPageDto, HttpServletRequest request, HttpServletResponse httpResponse) {
if (null == payPageDto || null == payPageDto.getTotal()) {
......@@ -139,11 +145,20 @@ public class AliPayServiceImpl implements AliPayService {
httpResponse.getWriter().flush();
httpResponse.getWriter().close();
return R.ok();
//增加用户查询次数和充值记录
AddLimitVo addLimitVo = new AddLimitVo();
addLimitVo.setPayMoney(payPageDto.getTotal());
addLimitVo.setPayType(1);
addLimitVo.setUserId(payPageDto.getUserId());
R<Boolean> booleanR = userLimitService.addLimit(addLimitVo);
if (booleanR.getCode()==1) {
return R.error("用户查询次数添加失败");
}
return R.ok(0,"充值成功");
} catch (Exception e) {
e.printStackTrace();
return R.ok(1,"充值失败");
}
return R.ok();
}
@Override
......
......@@ -81,7 +81,7 @@ public class SendSmsSerViceImpl implements SendSmsSerVice {
map.put("code", code);
request.putQueryParameter("RegionId", "cn-hangzhou");
request.putQueryParameter("PhoneNumbers", sendSmsVo.getPhone());
request.putQueryParameter("SignName", "山东宇嘉雪教育科技有限公司");
request.putQueryParameter("SignName", "山东宇嘉雪教育");
if (sendSmsVo.getScene()==1) {
request.putQueryParameter("TemplateCode", "SMS_211755494");
}
......
......@@ -3,6 +3,8 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.dto.PayPageDto;
import cn.wisenergy.model.dto.PayQueryDto;
import cn.wisenergy.model.vo.AddLimitVo;
import cn.wisenergy.service.app.UserLimitService;
import cn.wisenergy.service.app.WxPayService;
import cn.wisenergy.service.httpClient.WechatPayHttpClientBuilder;
......@@ -28,6 +30,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.After;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -50,6 +53,9 @@ import java.util.UUID;
@Service
@Slf4j
public class WxPayServiceImpl implements WxPayService {
@Autowired
private UserLimitService userLimitService;
/**
* 商户号
*/
......@@ -88,7 +94,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override
public R<String> wxPay(PayPageDto payPageDto) throws UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException {
public R<String> wxPay(PayPageDto payPageDto) {
if (null == payPageDto || null == payPageDto.getTotal()) {
return R.error("入参不能为空!");
}
......@@ -111,10 +117,24 @@ public class WxPayServiceImpl implements WxPayService {
jsonObject.put("out_trade_no", tradeNo);
jsonObject.put("notify_url", WxCommon.NOTIFY_URL);
jsonObject.put("amount", payPageDto);
String sign = SignDemo.getToken(method, httpurl, jsonObject.toJSONString(), nonceStr, timestamp);
httpPost.setHeader("Authorization", "WECHATPAY2-SHA256-RSA2048" + " " + sign);
return null;
String sign = null;
try {
sign = SignDemo.getToken(method, httpurl, jsonObject.toJSONString(), nonceStr, timestamp);
httpPost.setHeader("Authorization", "WECHATPAY2-SHA256-RSA2048" + " " + sign);
//增加用户查询次数和充值记录
AddLimitVo addLimitVo = new AddLimitVo();
addLimitVo.setPayMoney(payPageDto.getTotal());
addLimitVo.setPayType(2);
addLimitVo.setUserId(payPageDto.getUserId());
R<Boolean> booleanR = userLimitService.addLimit(addLimitVo);
if (booleanR.getCode()==1) {
return R.error("用户查询次数添加失败");
}
return R.ok(0,"充值成功");
} catch (Exception e) {
return R.ok(1,"充值失败");
}
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment