支付逻辑修改

This commit is contained in:
hanrenchun 2025-12-12 17:20:23 +08:00
parent e28ed3508f
commit b8e517af31
13 changed files with 188 additions and 59 deletions

View File

@ -1,11 +1,13 @@
package com.ruoyi.database.controller; package com.ruoyi.database.controller;
import cn.hutool.json.JSONObject;
import com.alipay.api.internal.util.AlipaySignature; import com.alipay.api.internal.util.AlipaySignature;
import com.ruoyi.config.AlipayRYConfig; import com.ruoyi.config.AlipayRYConfig;
import com.ruoyi.database.domain.ParkingBillInfo; import com.ruoyi.database.domain.ParkingBillInfo;
import com.ruoyi.database.domain.ParkingBillPaymentInfo; import com.ruoyi.database.domain.ParkingBillPaymentInfo;
import com.ruoyi.database.service.ParkingBillInfoService; import com.ruoyi.database.service.ParkingBillInfoService;
import com.ruoyi.database.service.ParkingBillPaymentInfoService; import com.ruoyi.database.service.ParkingBillPaymentInfoService;
import com.ruoyi.database.util.HaiKangApiUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -26,6 +28,9 @@ public class AlipayNotifyController {
@Autowired @Autowired
private ParkingBillInfoService parkingBillInfoService; private ParkingBillInfoService parkingBillInfoService;
@Autowired
private HaiKangApiUtils haiKangApiUtils;
public AlipayNotifyController(AlipayRYConfig alipayConfig) { public AlipayNotifyController(AlipayRYConfig alipayConfig) {
@ -91,6 +96,12 @@ public class AlipayNotifyController {
if (parkingBillInfo == null) { if (parkingBillInfo == null) {
return "failure"; return "failure";
} }
String notice = haiKangApiUtils.notice(one, parkingBillInfo, 2);
JSONObject jsonObject = new JSONObject(notice);
String msg = jsonObject.getStr("msg");
if ("SUCCESS".equals(msg)) {
parkingBillInfo.setIsNotify(1);
}
parkingBillInfo.setIsPay(1); parkingBillInfo.setIsPay(1);
boolean b1 = parkingBillInfoService.updateById(parkingBillInfo); boolean b1 = parkingBillInfoService.updateById(parkingBillInfo);
if (!b1) { if (!b1) {

View File

@ -18,8 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -35,8 +33,7 @@ public class SmallProgramController extends BaseController {
private final ParkingBillInfoService parkingBillInfoService; private final ParkingBillInfoService parkingBillInfoService;
private final AlipayService alipayService; private final AlipayService alipayService;
private final WechatPhoneService wechatPhoneService; private final BaseCustomerInfoService baseCustomerInfoService;
private final AlipayPhoneService alipayPhoneService;
private final WechatMiniProgramPayService wechatMiniProgramPayService; private final WechatMiniProgramPayService wechatMiniProgramPayService;
private final ParkingBillPaymentInfoService parkingBillPaymentInfoService; private final ParkingBillPaymentInfoService parkingBillPaymentInfoService;
private final CustomerPlateNoInfoService customerPlateNoInfoService; private final CustomerPlateNoInfoService customerPlateNoInfoService;
@ -48,15 +45,15 @@ public class SmallProgramController extends BaseController {
@ApiOperation("根据车牌号查询缴费订单") @ApiOperation("根据车牌号查询缴费订单")
@Transactional @Transactional
public AjaxResult getOrder(String plateNo) { public AjaxResult getOrder(String plateNo) {
// ParkingBillInfo b = parkingBillInfoService.saveOrUpdateParkingBillInfo(plateNo); ParkingBillInfo one = parkingBillInfoService.saveOrUpdateParkingBillInfo(plateNo);
ParkingBillInfo one = parkingBillInfoService.lambdaQuery() // ParkingBillInfo one = parkingBillInfoService.lambdaQuery()
.eq(ParkingBillInfo::getPlateNo, plateNo) // .eq(ParkingBillInfo::getPlateNo, plateNo)
.orderByDesc(ParkingBillInfo::getCreateTime) // .orderByDesc(ParkingBillInfo::getCreateTime)
.last("limit 1") // .last("limit 1")
.one(); // .one();
if (one == null) { if (one == null) {
return AjaxResult.error("未查询到订单"); return AjaxResult.error("未查询到停车记录");
}else { }else {
ParkingBillInfoVO parkingBillInfoVO = new ParkingBillInfoVO(); ParkingBillInfoVO parkingBillInfoVO = new ParkingBillInfoVO();
BeanUtils.copyProperties(one, parkingBillInfoVO); BeanUtils.copyProperties(one, parkingBillInfoVO);
@ -73,6 +70,9 @@ public class SmallProgramController extends BaseController {
@ApiOperation("历史缴费车牌列表") @ApiOperation("历史缴费车牌列表")
public AjaxResult getHistoryOrder(HttpServletRequest request){ public AjaxResult getHistoryOrder(HttpServletRequest request){
LoginUserByPhone loginUserByPhone = tokenService.getLoginUserByPhone(request); LoginUserByPhone loginUserByPhone = tokenService.getLoginUserByPhone(request);
if (loginUserByPhone == null) {
return AjaxResult.error("用户未登录");
}
String phone = loginUserByPhone.getPhone(); String phone = loginUserByPhone.getPhone();
List<ParkingBillPaymentInfo> list = parkingBillPaymentInfoService.lambdaQuery() List<ParkingBillPaymentInfo> list = parkingBillPaymentInfoService.lambdaQuery()
.eq(ParkingBillPaymentInfo::getPhone, phone) .eq(ParkingBillPaymentInfo::getPhone, phone)
@ -101,6 +101,9 @@ public class SmallProgramController extends BaseController {
@ApiOperation("查询历史未缴费订单") @ApiOperation("查询历史未缴费订单")
public AjaxResult getHistoryNoPayOrder(HttpServletRequest request){ public AjaxResult getHistoryNoPayOrder(HttpServletRequest request){
LoginUserByPhone loginUserByPhone = tokenService.getLoginUserByPhone(request); LoginUserByPhone loginUserByPhone = tokenService.getLoginUserByPhone(request);
if (loginUserByPhone == null) {
return AjaxResult.error("用户未登录");
}
List<CustomerPlateNoInfo> list = customerPlateNoInfoService.lambdaQuery() List<CustomerPlateNoInfo> list = customerPlateNoInfoService.lambdaQuery()
.eq(CustomerPlateNoInfo::getPhone, loginUserByPhone.getPhone()) .eq(CustomerPlateNoInfo::getPhone, loginUserByPhone.getPhone())
.list(); .list();
@ -131,6 +134,9 @@ public class SmallProgramController extends BaseController {
@ApiOperation("查询已绑定车辆") @ApiOperation("查询已绑定车辆")
public AjaxResult getBindTheVehicle(HttpServletRequest request){ public AjaxResult getBindTheVehicle(HttpServletRequest request){
LoginUserByPhone loginUserByPhone = tokenService.getLoginUserByPhone(request); LoginUserByPhone loginUserByPhone = tokenService.getLoginUserByPhone(request);
if (loginUserByPhone == null) {
return AjaxResult.error("用户未登录");
}
List<CustomerPlateNoInfo> list = customerPlateNoInfoService.lambdaQuery() List<CustomerPlateNoInfo> list = customerPlateNoInfoService.lambdaQuery()
.eq(CustomerPlateNoInfo::getPhone, loginUserByPhone.getPhone()) .eq(CustomerPlateNoInfo::getPhone, loginUserByPhone.getPhone())
.list(); .list();
@ -178,14 +184,30 @@ public class SmallProgramController extends BaseController {
.last("limit 1") .last("limit 1")
.one(); .one();
if (one == null) { if (one == null) {
return AjaxResult.error("订单查询失败"); return AjaxResult.error("停车记录查询失败");
}
ParkingBillInfo parkingBillInfo = parkingBillInfoService.saveOrUpdateParkingBillInfo(one.getPlateNo());
if (parkingBillInfo != null) {
one = parkingBillInfo;
} }
// one = parkingBillInfoService.saveOrUpdateParkingBillInfo(one.getPlateNo());
// if (one == null) {
// return AjaxResult.error("订单查询失败");
// }
String generate = generate(loginUserByPhone.getPhone()); String generate = generate(loginUserByPhone.getPhone());
String openId = getOpenId(payFees); BaseCustomerInfo one1 = baseCustomerInfoService.lambdaQuery()
.eq(BaseCustomerInfo::getPhone, loginUserByPhone.getPhone())
.last("limit 1")
.one();
if (one1 == null) {
return AjaxResult.error("用户信息出错");
}
String openId = null;
PayType payType = PayType.getByCode(payFees.getPayType());
switch (payType) {
case WECHAT:
openId = one1.getOpenId();
break;
case ALIPAY:
openId = one1.getAlipayUserId();
break;
}
String clientIp = wechatMiniProgramPayService.getClientIpAddress(request); String clientIp = wechatMiniProgramPayService.getClientIpAddress(request);
Map<String, Object> order = createOrder(payFees, generate, openId, one, clientIp); Map<String, Object> order = createOrder(payFees, generate, openId, one, clientIp);
@ -208,25 +230,7 @@ public class SmallProgramController extends BaseController {
} }
/**
* 获取用户openid
* @param payFees
* @return
*/
private String getOpenId(PayFees payFees) {
PayType payType = PayType.getByCode(payFees.getPayType());
switch (payType) {
case WECHAT:
return wechatPhoneService.getOpenId(payFees.getCode());
case ALIPAY:
return alipayPhoneService.getAlipayUserId(payFees.getCode());
default:
throw new IllegalArgumentException("不支持的登录方式: " + payType);
}
}
/** /**
* 创建支付宝 微信 订单 * 创建支付宝 微信 订单

View File

@ -1,5 +1,6 @@
package com.ruoyi.database.controller; package com.ruoyi.database.controller;
import cn.hutool.json.JSONObject;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.WxPayService;
@ -8,6 +9,7 @@ import com.ruoyi.database.domain.ParkingBillPaymentInfo;
import com.ruoyi.database.service.ParkingBillInfoService; import com.ruoyi.database.service.ParkingBillInfoService;
import com.ruoyi.database.service.ParkingBillPaymentInfoService; import com.ruoyi.database.service.ParkingBillPaymentInfoService;
import com.ruoyi.database.service.WechatMiniProgramPayService; import com.ruoyi.database.service.WechatMiniProgramPayService;
import com.ruoyi.database.util.HaiKangApiUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -27,6 +29,9 @@ public class WxPayNotifyController {
@Autowired @Autowired
private ParkingBillInfoService parkingBillInfoService; private ParkingBillInfoService parkingBillInfoService;
@Autowired
private HaiKangApiUtils haiKangApiUtils;
/** /**
* 微信支付结果通知回调 * 微信支付结果通知回调
@ -74,6 +79,12 @@ public class WxPayNotifyController {
if (parkingBillInfo == null) { if (parkingBillInfo == null) {
return WxPayNotifyResponse.fail("处理失败"); return WxPayNotifyResponse.fail("处理失败");
} }
String notice = haiKangApiUtils.notice(one, parkingBillInfo, 3);
JSONObject jsonObject = new JSONObject(notice);
String msg = jsonObject.getStr("msg");
if ("SUCCESS".equals(msg)) {
parkingBillInfo.setIsNotify(1);
}
parkingBillInfo.setIsPay(1); parkingBillInfo.setIsPay(1);
boolean b1 = parkingBillInfoService.updateById(parkingBillInfo); boolean b1 = parkingBillInfoService.updateById(parkingBillInfo);
if (!b1){ if (!b1){

View File

@ -2,6 +2,7 @@ package com.ruoyi.database.domain;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
@ -113,4 +114,8 @@ public class BaseCustomerInfo {
private Integer memberLevel; private Integer memberLevel;
@TableField(exist = false)
private String wxMchId;
} }

View File

@ -21,4 +21,9 @@ public class LoginRequest {
@NotBlank(message = "授权code不能为空") @NotBlank(message = "授权code不能为空")
private String code; private String code;
@ApiModelProperty("支付宝的授权code")
private String authCode;
} }

View File

@ -1,5 +1,6 @@
package com.ruoyi.database.domain; package com.ruoyi.database.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
@ -10,6 +11,7 @@ import java.util.Date;
* 停车场账单信息 * 停车场账单信息
*/ */
@Data @Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ParkingBill { public class ParkingBill {
/** /**

View File

@ -170,4 +170,9 @@ public class ParkingBillInfo {
@ApiModelProperty("是否支付") @ApiModelProperty("是否支付")
@Excel(name = "是否支付") @Excel(name = "是否支付")
private Integer isPay; private Integer isPay;
@ApiModelProperty("是否通知")
@Excel(name = "是否通知")
private Integer isNotify;
} }

View File

@ -15,8 +15,4 @@ public class PayFees {
@ApiModelProperty("支付方式: wechat 或 alipay") @ApiModelProperty("支付方式: wechat 或 alipay")
@NotBlank(message = "支付方式不能为空") @NotBlank(message = "支付方式不能为空")
private String payType; private String payType;
@ApiModelProperty("微信或支付宝的授权code")
@NotBlank(message = "code不能为空")
private String code;
} }

View File

@ -329,11 +329,11 @@ public class AlipayPhoneService {
*/ */
public String getAlipayUserId(String authCode) { public String getAlipayUserId(String authCode) {
try { try {
String phoneNumber = getPhoneNumber(authCode); String openId = getOpenId(authCode);
// 在实际业务中你可能需要根据手机号关联用户ID // 在实际业务中你可能需要根据手机号关联用户ID
// 这里返回手机号作为示例实际应该返回支付宝用户ID // 这里返回手机号作为示例实际应该返回支付宝用户ID
return phoneNumber; return openId;
} catch (Exception e) { } catch (Exception e) {
log.error("获取支付宝用户ID异常", e); log.error("获取支付宝用户ID异常", e);

View File

@ -50,7 +50,7 @@ public class ParkingBillInfoServiceImpl extends ServiceImpl<ParkingBillInfoMappe
parkingBillInfo.setDeductMoneyYuan(vehicleRecord.getDeductMoneyYuan()); parkingBillInfo.setDeductMoneyYuan(vehicleRecord.getDeductMoneyYuan());
parkingBillInfo.setTotalCostYuan(vehicleRecord.getTotalCostYuan()); parkingBillInfo.setTotalCostYuan(vehicleRecord.getTotalCostYuan());
LambdaUpdateWrapper<ParkingBillInfo> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<ParkingBillInfo> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(ParkingBillInfo::getBillCode,parkingBillInfo.getBillCode()); updateWrapper.eq(ParkingBillInfo::getInUnid,parkingBillInfo.getInUnid());
boolean b = saveOrUpdate(parkingBillInfo, updateWrapper); boolean b = saveOrUpdate(parkingBillInfo, updateWrapper);
if (b) { if (b) {
return parkingBillInfo; return parkingBillInfo;

View File

@ -4,19 +4,28 @@ import cn.hutool.json.JSONObject;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.database.domain.ParkingBillInfo;
import com.ruoyi.database.domain.ParkingBillPaymentInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -73,27 +82,36 @@ public class HaiKangApiUtils {
* 调用海康云平台 * 调用海康云平台
* 获取accessToken接口 * 获取accessToken接口
*/ */
public String getHikAccessToken(){ public String getHikAccessToken() {
try (CloseableHttpClient client = createHttpClient()) { try (CloseableHttpClient client = createHttpClient()) {
HttpPost httpPost = new HttpPost(HIK_URL + "/artemis/oauth/token"); HttpPost httpPost = new HttpPost(HIK_URL + "/artemis/oauth/token");
HashMap<String, String> map = new HashMap<>();
map.put("client_id", client_id); // 1. 使用List<NameValuePair>构建表单参数
map.put("client_secret", client_secret); List<NameValuePair> params = new ArrayList<>();
String json = gson.toJson(map); params.add(new BasicNameValuePair("client_id", client_id));
StringEntity entity = new StringEntity(json, "UTF-8"); params.add(new BasicNameValuePair("client_secret", client_secret));
// 2. 创建UrlEncodedFormEntity
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
httpPost.setEntity(entity); httpPost.setEntity(entity);
// 3. 设置正确的Content-Type
httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
CloseableHttpResponse response = client.execute(httpPost);
// 4. 如果API需要Basic认证
String auth = client_id + ":" + client_secret;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
httpPost.setHeader("Authorization", "Basic " + encodedAuth);
try (CloseableHttpResponse response = client.execute(httpPost)) {
HttpEntity entityResponse = response.getEntity(); HttpEntity entityResponse = response.getEntity();
if (entityResponse != null) { if (entityResponse != null) {
String res = EntityUtils.toString(entityResponse, "UTF-8"); return EntityUtils.toString(entityResponse, "UTF-8");
System.out.println(res);
return res;
} else { } else {
// 处理空响应的情况
System.err.println("Received empty response from server"); System.err.println("Received empty response from server");
return null; return null;
} }
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
@ -157,4 +175,38 @@ public class HaiKangApiUtils {
} }
} }
public String notice(ParkingBillPaymentInfo billPaymentInfo,ParkingBillInfo parkingBillInfo,int payType){
try (CloseableHttpClient client = createHttpClient()) {
HttpPost httpPost = new HttpPost(HIK_URL + "/artemis/api/v1/charge/payment/notice");
HashMap<String, Object> map = new HashMap<>();
map.put("billNo", billPaymentInfo.getBillCode());
map.put("thirdBillNo", billPaymentInfo.getTransactionId());
map.put("payTime", billPaymentInfo.getPayTime());
map.put("payType", payType);
map.put("payMoney", parkingBillInfo.getPayMoney());
map.put("thirdUserId", billPaymentInfo.getOpenId());
String json = gson.toJson(map);
StringEntity entity = new StringEntity(json, "UTF-8");
httpPost.setEntity(entity);
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("access_token", getAccessToken());
CloseableHttpResponse response = client.execute(httpPost);
HttpEntity entityResponse = response.getEntity();
if (entityResponse != null) {
String res = EntityUtils.toString(entityResponse, "UTF-8");
System.out.println(res);
return res;
} else {
// 处理空响应的情况
System.err.println("Received empty response from server");
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
} }

View File

@ -22,6 +22,7 @@ import com.ruoyi.system.service.ISysMenuService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
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.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -58,6 +59,9 @@ public class SysLoginController {
@Autowired @Autowired
private AlipayPhoneService alipayPhoneService; private AlipayPhoneService alipayPhoneService;
@Value("${wx.pay.mchId}")
public String wxMchId;
/** /**
* 登录方法 * 登录方法
* *
@ -97,22 +101,35 @@ public class SysLoginController {
String phoneNumber = getPhoneNumberByLoginType(request); String phoneNumber = getPhoneNumberByLoginType(request);
LoginBodyByPhone loginBodyByPhone = new LoginBodyByPhone(); LoginBodyByPhone loginBodyByPhone = new LoginBodyByPhone();
loginBodyByPhone.setPhone(phoneNumber); loginBodyByPhone.setPhone(phoneNumber);
String openId = getOpenId(request);
LoginType loginType = LoginType.getByCode(request.getLoginType());
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
// 生成令牌 // 生成令牌
BaseCustomerInfo one = baseCustomerInfoService.lambdaQuery() BaseCustomerInfo one = baseCustomerInfoService.lambdaQuery()
.eq(BaseCustomerInfo::getPhone, loginBodyByPhone.getPhone()) .eq(BaseCustomerInfo::getPhone, loginBodyByPhone.getPhone())
.last("limit 1") .last("limit 1")
.one(); .one();
switch (loginType) {
case WECHAT:
one.setOpenId(openId);
break;
case ALIPAY:
one.setAlipayUserId(openId);
break;
}
if (one == null) { if (one == null) {
BaseCustomerInfo baseCustomerInfo = new BaseCustomerInfo(); BaseCustomerInfo baseCustomerInfo = new BaseCustomerInfo();
baseCustomerInfo.setPhone(loginBodyByPhone.getPhone()); baseCustomerInfo.setPhone(loginBodyByPhone.getPhone());
baseCustomerInfo.setNickname(loginBodyByPhone.getPhone()); baseCustomerInfo.setNickname(loginBodyByPhone.getPhone());
baseCustomerInfoService.save(baseCustomerInfo); baseCustomerInfoService.save(baseCustomerInfo);
}else {
baseCustomerInfoService.updateById(one);
} }
String token = loginService.loginByPhone(loginBodyByPhone.getPhone()); String token = loginService.loginByPhone(loginBodyByPhone.getPhone());
ajax.put(Constants.TOKEN, token); ajax.put(Constants.TOKEN, token);
return ajax; return ajax;
} }
@ -149,6 +166,26 @@ public class SysLoginController {
throw new IllegalArgumentException("不支持的登录方式: " + loginType); throw new IllegalArgumentException("不支持的登录方式: " + loginType);
} }
} }
/**
* 获取用户openid
* @param request
* @return
*/
private String getOpenId(LoginRequest request) {
LoginType loginType = LoginType.getByCode(request.getLoginType());
switch (loginType) {
case WECHAT:
return wechatPhoneService.getOpenId(request.getAuthCode());
case ALIPAY:
return alipayPhoneService.getAlipayUserId(request.getAuthCode());
default:
throw new IllegalArgumentException("不支持的登录方式: " + loginType);
}
}
/** /**
* 获取用户信息 * 获取用户信息
* *
@ -188,6 +225,7 @@ public class SysLoginController {
.last("limit 1") .last("limit 1")
.one(); .one();
one.setPhone(DesensitizedUtil.mobilePhone(one.getPhone())); one.setPhone(DesensitizedUtil.mobilePhone(one.getPhone()));
one.setWxMchId(wxMchId);
return AjaxResult.success(one); return AjaxResult.success(one);
} }
return AjaxResult.success(loginUser); return AjaxResult.success(loginUser);

View File

@ -138,7 +138,7 @@ wx:
appId: wxea120f6f0e955dc2 # 你的小程序AppID appId: wxea120f6f0e955dc2 # 你的小程序AppID
mchId: 1251484401 # 你的商户号 mchId: 1251484401 # 你的商户号
mchKey: QloRc8RZcKpOVb4hKPFJKRG9stmqSfxD # 你的API密钥(32位) mchKey: QloRc8RZcKpOVb4hKPFJKRG9stmqSfxD # 你的API密钥(32位)
keyPath: classpath:cert/apiclient_cert.p12 # 证书路径 keyPath: /home/project/wisdomPark/config/apiclient_cert.p12 # 证书路径
notifyUrl: https://tingche.csckl.com/wisdomPark/wxpay/notify notifyUrl: https://tingche.csckl.com/wisdomPark/wxpay/notify
alipay: alipay: