修改项目名称

This commit is contained in:
韩鹏辉 2023-08-03 14:50:27 +08:00
parent 2a16994378
commit eebaa66f43
24 changed files with 920 additions and 2 deletions

View File

@ -45,6 +45,8 @@ public class AgencyService {
@Autowired
TbPlussMerchantBackLklMapper tbPlussMerchantBackLklMapper;
@Autowired
TbPlussMerchantBaseInfoMapper tbPlussMerchantBaseInfoMapper;
@ -192,6 +194,26 @@ public class AgencyService {
list1.add(hashMap);
}
}
Map<String,Object> stringObjectMap=new HashMap<>();
TbPlussMerchantBaseInfo baseInfo=tbPlussMerchantBaseInfoMapper.selectByUserId(id);
if(ObjectUtil.isNotEmpty(baseInfo)){
stringObjectMap.put("merchantCode",baseInfo.getMerchantcode());
stringObjectMap.put("alias",baseInfo.getAlias());
stringObjectMap.put("merchantType",baseInfo.getMerchanttype());
switch (baseInfo.getMerchanttype()){
case "1":
stringObjectMap.put("merchantTypeName","小微");
break;
case "2":
stringObjectMap.put("merchantTypeName","个体");
break;
case "3":
stringObjectMap.put("merchantTypeName","企业");
break;
}
}
it.put("merchantBaseInfo",stringObjectMap);
it.put("merchantChannel",list1);
}
);

View File

@ -0,0 +1,67 @@
package com.chaozhanggui.common.system.config;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 统一API响应结果封装
* @author DJH
*/
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
private int code;
private String message;
private T data;
private String respCode;
private T list;
private String totalCount;
private String timestamp;
public Result<T> setCode(ResultCode resultCode) {
this.code = resultCode.code();
return this;
}
public Result(ResultCode resultCode, String message) {
this(resultCode, message, null);
}
public Result(ResultCode resultCode, String message, T data) {
this.code = resultCode.code();
this.message = message;
this.data = data;
timestamp = DateUtil.format(new Date(), "yyyyMMddHHmmss");
}
public Result(int code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
timestamp = DateUtil.format(new Date(), "yyyyMMddHHmmss");
}
public Result(int code, String message) {
this.code = code;
this.message = message;
timestamp = DateUtil.format(new Date(), "yyyyMMddHHmmss");
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
}

View File

@ -0,0 +1,41 @@
package com.chaozhanggui.common.system.config;
/**
* 响应码枚举参考HTTP状态码的语义
*/
public enum ResultCode {
//成功
SUCCESS(200),
//失败
FAIL(400),
//未认证签名错误
UNAUTHORIZED(401),
//未认证签名错误
PARAM_ERROR(422),
// 403
FORBIDDEN(403),
//接口不存在
NOT_FOUND(404),
//服务器内部错误
INTERNAL_SERVER_ERROR(500),
// 服务不可达
SERVICE_UNAVAILABLE(503),
//未认证签名错误
NOT_TOKEN(401),
//无数据
UNDEFINDE(201),
/**
* 交易未知 查询交易结果
*/
TRANSUNKNOW(202);
private final int code;
ResultCode(int code) {
this.code = code;
}
public int code() {
return code;
}
}

View File

@ -0,0 +1,97 @@
package com.chaozhanggui.common.system.config;
import com.alibaba.fastjson.JSONObject;
/**
* 响应结果生成工具
*/
public class ResultGenerator {
public static final String DEFAULT_SUCCESS_MESSAGE = "操作成功";
public static final String DEFAULT_FAIL_MESSAGE = "操作失败!";
public static <T> Result<T> genSuccessResult() {
return new Result()
.setCode(ResultCode.SUCCESS)
.setMessage(DEFAULT_SUCCESS_MESSAGE);
}
public static Result genUndefinedResult(String message) {
return new Result()
.setCode(ResultCode.UNDEFINDE)
.setMessage(message);
}
public static <T> Result<T> genSuccessResult(String msg, T data) {
return new Result<>(ResultCode.SUCCESS, msg, data);
}
public static <T> Result<T> genSuccessResult(T data) {
return new Result<>(ResultCode.SUCCESS, DEFAULT_SUCCESS_MESSAGE, data);
}
public static <T> Result<T> genResult(String data) {
return new Result<>(ResultCode.SUCCESS, data);
}
public static Result genTransunKonwResult(String message) {
return new Result<>().setCode(ResultCode.TRANSUNKNOW).setMessage(message);
}
public static <T> Result<T> genTransunKonwResult(String message,T data){
return new Result<>(ResultCode.TRANSUNKNOW, message, data);
}
public static <T> Result<T> genFailResult(String message) {
return new Result<>(ResultCode.FAIL, message, null);
}
public static <T> Result<T> genFailResult(String message,T data) {
return new Result<>(ResultCode.FAIL, message, data);
}
public static <T> Result<T> genFailResult(T data) {
return new Result<>(ResultCode.FAIL, DEFAULT_FAIL_MESSAGE, data);
}
public static JSONObject genFailJsonResult(String message) {
JSONObject result = new JSONObject();
result.put("code",ResultCode.FAIL.code());
result.put("message",message);
result.put("data",null);
return result;
}
public static JSONObject genSuccessJsonResult(String message,Object data) {
JSONObject result = new JSONObject();
result.put("code",ResultCode.SUCCESS.code());
result.put("message",message);
result.put("data",data);
return result;
}
public static JSONObject genSuccessJsonResult(Object data) {
JSONObject result = new JSONObject();
result.put("code",ResultCode.SUCCESS.code());
result.put("message","请求成功");
result.put("data",data);
return result;
}
public static JSONObject genSuccessJsonPos(Object data, String appId, String requestId) {
JSONObject result = new JSONObject();
result.put("code","0000");
result.put("msg","操作成功");
result.put("appId", appId);
result.put("requestId", requestId);
result.put("respData", data);
return result;
}
public static JSONObject genFailJsonPos(String msg, String appId, String requestId) {
JSONObject result = new JSONObject();
result.put("code","400");
result.put("msg", msg);
result.put("appId", appId);
result.put("requestId", requestId);
return result;
}
}

View File

@ -0,0 +1,40 @@
package com.chaozhanggui.common.system.myEnum;
import com.chaozhanggui.common.system.config.MsgException;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 结算类型枚举
* @author Administrator
* @date 2021/07/12
*/
@Getter
@AllArgsConstructor
public enum SettleTypeEnum {
D0("D0",0,"D0实时结算"),
D1("D1",1,"D1次日结算");
private String code;
private Integer value;
private String name;
public static boolean checkValues(String code) {
SettleTypeEnum[] settleTypeEnums = values();
boolean flag = false;
for (SettleTypeEnum businessModeEnum : settleTypeEnums) {
if(businessModeEnum.getCode().equals(code)){
flag = true;
}
}
if(!flag){
MsgException.throwException("结算参数有误!");
}
return true;
}
}

View File

@ -0,0 +1,83 @@
package com.chaozhanggui.common.system.util;
import java.security.MessageDigest;
public class MD5Util {
private static String byteArrayToHexString(byte b[]) {
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++)
resultSb.append(byteToHexString(b[i]));
return resultSb.toString();
}
private static String byteToHexString(byte b) {
int n = b;
if (n < 0)
n += 256;
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}
public static String MD5Encode(String origin, String charsetname) {
String resultString = null;
try {
resultString = origin;
MessageDigest md = MessageDigest.getInstance("MD5");
if (charsetname == null || "".equals(charsetname))
resultString = byteArrayToHexString(md.digest(resultString
.getBytes()));
else
resultString = byteArrayToHexString(md.digest(resultString
.getBytes(charsetname)));
} catch (Exception exception) {
}
return resultString;
}
private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
/**
* MD5指纹算法
*
* @param str
* @return
*/
public static String md5(String str) {
if (str == null) {
return null;
}
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
return bytesToHexString(messageDigest.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 将二进制转换成16进制
*
* @param src
* @return
*/
public static String bytesToHexString(byte[] src) {
StringBuilder stringBuilder = new StringBuilder("");
if (src == null || src.length <= 0) {
return null;
}
for (int i = 0; i < src.length; i++) {
int v = src[i] & 0xFF;
String hv = Integer.toHexString(v);
if (hv.length() < 2) {
stringBuilder.append(0);
}
stringBuilder.append(hv);
}
return stringBuilder.toString();
}
}

View File

@ -0,0 +1,160 @@
package com.chaozhanggui.common.system.util;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Map;
import java.util.TreeMap;
/**
* 签名工具类
*/
@Slf4j
public class SignUtils {
/**
* 获取签名之前的源串 按照ASCII 排序
*
* @param object
* @return
*/
public static String getSignContent(JSONObject object) {
TreeMap<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(object), TreeMap.class);
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Object> o : map.entrySet()) {
String key = o.getKey();
Object value = o.getValue();
if ("sign".contains(key)) {
continue;
}
if (value != null) {
sb.append(key).append("=").append(value).append("&");
// if(value instanceof ArrayList || value instanceof Map){
// sb.append(key).append("=").append(JSON.toJSONString(value)).append("&");
// }else{
// sb.append(key).append("=").append(value).append("&");
// }
}
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
public static String wapGetSign(JSONObject object,String key) {
String checkSign = MD5Util.MD5Encode(getSignContent(object) + "&key=" + key, "UTF-8");
return checkSign;
}
/**
* 获取签名之前的源串 按照ASCII 排序
*
* @param object
* @return
*/
public static String getYSSignContent(JSONObject object) {
String s = JSONObject.toJSONString(object);
TreeMap<String, Object> map = JSONObject.parseObject(s, TreeMap.class);
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Object> o : map.entrySet()) {
String key = o.getKey();
Object value = o.getValue();
if ("sign".contains(key)) {
continue;
}
if (ObjectUtil.isNotEmpty(value)) {
sb.append(key).append("=").append(value).append("&");
}
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
public static String getSignContent1(JSONObject object,String appSerct) {
TreeMap<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(object), TreeMap.class);
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Object> o : map.entrySet()) {
String key = o.getKey();
Object value = o.getValue();
if ("sign".contains(key)) {
continue;
}
if (ObjectUtil.isNotEmpty(value)) {
sb.append(key).append(value);
}
}
sb.append(appSerct);
return sb.toString();
}
public static String sha1Encrypt(String str) {
if (str == null || str.length() == 0) {
return null;
}
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
try {
MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
mdTemp.update(str.getBytes(StandardCharsets.UTF_8));
byte[] md = mdTemp.digest();
int j = md.length;
char[] buf = new char[j * 2];
int k = 0;
for (byte byte0 : md) {
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
buf[k++] = hexDigits[byte0 & 0xf];
}
return new String(buf);
} catch (Exception e) {
return null;
}
}
public static String HMACSHA256BYTE(String data, String key) {
String hash = "";
try {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] array = sha256_HMAC.doFinal(data.getBytes());
hash = Base64.encodeBase64String(array);
} catch (Exception e) {
e.printStackTrace();
}
return hash;
}
public static String getSignSha256(JSONObject params, String accessKeySecret) {
return HMACSHA256BYTE(getSignContent(params),accessKeySecret);
}
/**
* 获取圆通签名
* @date: 2022/2/24 17:00
* @param param:
* @param secret:
* @param method:
* @param version:
* @return java.lang.String
*/
public static String getYtSign(String param, String secret,String method,String version) {
String data = param + method + version;
String sign;
try {
byte[] signByte = DigestUtils.md5(data + secret);
sign = Base64.encodeBase64String(signByte);
} catch (Throwable e) {
log.error("加密失败.e:{}.", e.toString());
sign = "ERROR";
}
return sign;
}
}

View File

@ -21,4 +21,6 @@ public interface TbPlussMerchantBaseInfoMapper {
int updateByPrimaryKey(TbPlussMerchantBaseInfo record);
TbPlussMerchantBaseInfo selectByUserId(String userId);
TbPlussMerchantBaseInfo selectByMerchantcode(String merchantcode);
}

View File

@ -30,4 +30,11 @@ public interface TbPlussMerchantChannelStatusMapper {
Map<String,Object> selectByUserId(@Param("userId") String userId, @Param("channel") String channel);
TbPlussMerchantChannelStatus getByMerchantCode(@Param("merchantCode") String merchantCode,@Param("channel") String channel );
TbPlussMerchantChannelStatus getValidData(String merchantCode);
}

View File

@ -27,5 +27,7 @@ public interface TbPlussMerchantOrderMapper {
List<TaskOrderSum> selectByUserId();
List<TbPlussMerchantOrder> selectByMercorderno(String mercorderno);
}

View File

@ -3,6 +3,7 @@ package com.chaozhanggui.dao.system.dao;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantStore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
@Component
@ -19,4 +20,8 @@ public interface TbPlussMerchantStoreMapper {
int updateByPrimaryKeySelective(TbPlussMerchantStore record);
int updateByPrimaryKey(TbPlussMerchantStore record);
TbPlussMerchantStore getStoreByMerchantCode(String merchantCode);
TbPlussMerchantStore selectByIdOrMerchantCode(@Param("id") Integer id,@Param("merchantCode") String merchantCode);
}

View File

@ -19,4 +19,6 @@ public interface TbPlussSubMercCodeYsMapper {
int updateByPrimaryKeySelective(TbPlussSubMercCodeYs record);
int updateByPrimaryKey(TbPlussSubMercCodeYs record);
TbPlussSubMercCodeYs selectByCityName(String cityName);
}

View File

@ -281,4 +281,14 @@ public class TbPlussMerchantChannelStatus implements Serializable {
public void setChannelName(String channelName) {
this.channelName = channelName;
}
public boolean isPayment() {
boolean flag = false;
if ("3".equals(this.getStatus()) || "4".equals(this.getStatus()) || "6".equals(this.getStatus())) {
flag = true;
}
return flag;
}
}

View File

@ -591,4 +591,8 @@
select * from tb_pluss_merchant_base_info where userId=#{userId}
</select>
<select id="selectByMerchantcode" resultMap="BaseResultMap">
select * from tb_pluss_merchant_base_info where merchantCode=#{merchantcode}
</select>
</mapper>

View File

@ -372,4 +372,21 @@
left join tb_pluss_merchant_channel c on s.channel=c.id
where b.userId=#{userId} and s.channel=#{channel}
</select>
<select id="getByMerchantCode" resultMap="BaseResultMap">
select * from tb_pluss_merchant_channel_status where merchantCode=#{merchantCode}
<choose>
<when test="channel !=null and channel !=''">
and channel=#{channel}
</when>
<otherwise>
and channel is null
</otherwise>
</choose>
</select>
<select id="getValidData" resultMap="BaseResultMap">
select * from tb_pluss_merchant_channel_status where merchantCode=#{merchantCode} and (`status`=3 or `status`=6) order by valid desc, id asc limit 1
</select>
</mapper>

View File

@ -732,4 +732,8 @@
GROUP BY
d.user_id
</select>
<select id="selectByMercorderno" resultMap="BaseResultMap">
select * from tb_pluss_merchant_order where mercOrderNo=#{mercorderno}
</select>
</mapper>

View File

@ -577,4 +577,18 @@
isMarket = #{ismarket,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="getStoreByMerchantCode" resultMap="BaseResultMap">
select * from tb_pluss_merchant_store where merchantCode=#{merchantCode}
</select>
<select id="selectByIdOrMerchantCode" resultMap="BaseResultMap">
select * from tb_pluss_merchant_store where 1=1
<if test="id !=null and id !=''">
and id=#{id}
</if>
<if test="merchantCode !=null and merchantCode !=''">
and merchantCode=#{merchantCode}
</if>
</select>
</mapper>

View File

@ -103,4 +103,8 @@
remark = #{remark,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByCityName" resultMap="BaseResultMap">
SELECT * FROM tb_pluss_sub_merc_code_ys WHERE `name` like CONCAT(#{cityName},'%') limit 1
</select>
</mapper>

View File

@ -5,11 +5,10 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.chaozhanggui.system</groupId>
<artifactId>admin-system</artifactId>
<artifactId>ysk-system</artifactId>
<version>1.0.0</version>
</parent>
<groupId>org.example</groupId>
<artifactId>merchant-service-api</artifactId>
<properties>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.chaozhanggui.system</groupId>
<artifactId>ysk-system</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>order-service</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.chaozhanggui.system</groupId>
<artifactId>common-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.chaozhanggui.system</groupId>
<artifactId>dao-api</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,4 @@
package com.chaozhanggui.system.order.controller;
public class OrderController {
}

View File

@ -0,0 +1,218 @@
package com.chaozhanggui.system.order.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.common.system.myEnum.SettleTypeEnum;
import com.chaozhanggui.common.system.util.MD5Util;
import com.chaozhanggui.common.system.util.SignUtils;
import com.chaozhanggui.dao.system.dao.*;
import com.chaozhanggui.dao.system.entity.*;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
public class OrderParamCheck {
private static final String KEY = "4c8d277b0f274604af68e590cc0b3e6b";
@Autowired
private TbPlussMerchantStoreMapper tbPlussMerchantStoreMapper;
@Autowired
private TbPlussMerchantBaseInfoMapper tbPlussMerchantBaseInfoMapper;
@Autowired
private TbPlussUserInfoMapper tbPlussUserInfoMapper;
@Autowired
private TbPlussMerchantOrderMapper tbPlussMerchantOrderMapper;
@Autowired
private TbPlussMerchantChannelStatusMapper tbPlussMerchantChannelStatusMapper;
public String currencyParamsCheck(JSONObject jsonObject){
Optional.ofNullable(jsonObject.getString("method")).orElseThrow(() -> new MsgException("接口方法参数不能为空"));
String mercOrderNo = jsonObject.getString("mercOrderNo");
Optional.ofNullable(mercOrderNo).orElseThrow(() -> new MsgException("商户订单号不能为空"));
if (mercOrderNo.length() < 10 || mercOrderNo.length() > 50) {
throw new MsgException("商户订单号长度格式有误长度介于10到50之间!");
}
Optional.ofNullable(jsonObject.getString("sign")).orElseThrow(() -> new MsgException("缺失签名sign参数"));
if("trans_pay".equals(jsonObject.getString("method")) ||
"trans_wap_pay".equals(jsonObject.getString("method")) ||
"trans_scan_pay".equals(jsonObject.getString("method"))){
TbPlussMerchantStore store = null;
if("trans_pay".equals(jsonObject.getString("method"))){
checSign(jsonObject,jsonObject.getString("merchantCode"));
store = checkTransPayParams(jsonObject,jsonObject.getString("merchantCode"));
}else{
Optional.ofNullable(jsonObject.getString("merchantCode")).orElseThrow(() -> new MsgException("商户编号不能为空!"));
checSign(jsonObject,jsonObject.getString("merchantCode"));
store = checkTransPayParams(jsonObject,jsonObject.getString("merchantCode"));
}
String payData = checkMercOrder(store, jsonObject);
if(StringUtil.isNotEmpty(payData)){
return payData;
}
TbPlussMerchantBaseInfo baseInfo = tbPlussMerchantBaseInfoMapper.selectByMerchantcode(store.getMerchantcode());
Optional.ofNullable(baseInfo).orElseThrow(() -> new MsgException("当前商户暂未完成商户认证功能!"));
// 全局电子围栏和单商户电子围栏判定
//TODO 先关闭异地支付
// if (!commonSwitchService.allowEcdemicPay() && !store.allowEcdemicPay()) {
// // 不允许异地支付的时候需要校验ip和商户所在城市
// try {
// merchantService.checkPayLocation(jsonObject.getString("ip"), baseInfo, jsonObject.getString("province"));
// } catch (PayRiskException e) {
// throw new MsgException(e.getMessage());
// }
// }
TbPlussMerchantChannelStatus channel = null;
if("trans_wap_pay".equals(jsonObject.getString("method"))){
channel = tbPlussMerchantChannelStatusMapper.getByMerchantCode(baseInfo.getMerchantcode(),"4");
}else{
channel = tbPlussMerchantChannelStatusMapper.getValidData(baseInfo.getMerchantcode());
}
MsgException.checkNull(channel,"无进件信息,请先提交商户信息进行审核");
if("4".equals(channel.getChannel()) && StringUtil.isNotEmpty(jsonObject.getString("settleType"))){
SettleTypeEnum.checkValues(jsonObject.getString("settleType"));
channel.setSettlementtype(jsonObject.getString("settleType"));
}
MsgException.check("7".equals(channel.getStatus()),"快付审核中");
MsgException.check(!channel.isPayment(),"进件未通过请耐心等待或联系客服");
jsonObject.put("channel", channel);
jsonObject.put("merchant", baseInfo);
jsonObject.put("store", store);
}
return null;
}
private void checSign(JSONObject jsonObject,String merchantCode) {
String sign = jsonObject.getString("sign");
jsonObject.remove("sign");
String md5Key = KEY;
Integer storeId = jsonObject.getInteger("storeId");
if(ObjectUtil.isNotEmpty(storeId)){
TbPlussMerchantStore store = tbPlussMerchantStoreMapper.selectByPrimaryKey(storeId);
MsgException.checkNull(store,"门店信息异常");
merchantCode = store.getMerchantcode();
}
String phone = jsonObject.getString("phone");
Integer sId = null;
if(StringUtil.isNotEmpty(merchantCode)){
TbPlussMerchantBaseInfo baseInfo = tbPlussMerchantBaseInfoMapper.selectByMerchantcode(merchantCode);
MsgException.checkNull(baseInfo,"商户号不存在");
if(baseInfo != null && StringUtil.isNotEmpty(baseInfo.getMd5key())){
md5Key = baseInfo.getMd5key();
}
}else if(StringUtil.isNotEmpty(phone)){
TbPlussUserInfo userInfo = tbPlussUserInfoMapper.selectByLoginName(phone);
MsgException.checkNull(userInfo,"手机号有误!");
TbPlussMerchantBaseInfo lists = tbPlussMerchantBaseInfoMapper.selectByUserId(userInfo.getId().toString());
if(ObjectUtil.isEmpty(lists)){
MsgException.throwException("商户信息异常!");
}
merchantCode = lists.getMerchantcode();
TbPlussMerchantStore store = tbPlussMerchantStoreMapper.getStoreByMerchantCode(merchantCode);
MsgException.checkNull(store,"门店信息异常!");
sId = store.getId();
}
String signContent = SignUtils.getSignContent(jsonObject) + "&key=" + md5Key;
log.info("============>签名源串:{}<==============", signContent);
String ckeckSign = MD5Util.MD5Encode(signContent, "UTF-8");
if (!sign.equalsIgnoreCase(ckeckSign)) {
log.info("============>签名校验失败,我方生成签名串:{},下游签名串:{}", ckeckSign, sign);
throw new MsgException("签名校验失败!");
}
if(ObjectUtil.isNotEmpty(sId)){
jsonObject.put("storeId",sId);
}
}
private TbPlussMerchantStore checkTransPayParams(JSONObject jsonObject,String merchantCode) {
Integer id = jsonObject.getInteger("storeId");
TbPlussMerchantStore store = new TbPlussMerchantStore();
if(StringUtil.isNotEmpty(merchantCode)){
store.setMerchantcode(merchantCode);
}else{
store.setId(id);
}
if(StringUtil.isEmpty(merchantCode) && id == null){
MsgException.throwException("缺失商户编号[merchantCode]参数!");
}
TbPlussMerchantStore storeInfo = tbPlussMerchantStoreMapper.selectByIdOrMerchantCode(store.getId(),store.getMerchantcode());
Optional.ofNullable(storeInfo).orElseThrow(() -> new MsgException("店铺数据异常!"));
String payAmt = jsonObject.getString("payAmt");
Optional.ofNullable(payAmt).orElseThrow(() -> new MsgException("付款金额不能为空!"));
if(StringUtil.isEmpty(storeInfo.getPayecdemicswitch()) || "0".equals(storeInfo.getPayecdemicswitch())){
String ip = jsonObject.getString("ip");
Optional.ofNullable(ip).orElseThrow(() -> new MsgException("付款人ip地址不能为空!"));
}
if (!ObjectUtil.isValidIfNumber(payAmt)) {
throw new MsgException("交易金额格式不正确,单位(元)!");
}
if (Double.parseDouble(payAmt) < 0.01d) {
throw new MsgException("交易金额最少为0.01!");
}
Optional.ofNullable(jsonObject.getString("notifyUrl"))
.orElseThrow(() -> new MsgException("异步通知地址不能为空!"));
String method = jsonObject.getString("method");
if(!"trans_scan_pay".equals(method)){
Optional.ofNullable(jsonObject.getString("payWay"))
.orElseThrow(() -> new MsgException("支付渠道不能为空!"));
}
if(StringUtil.isEmpty(merchantCode)){
Optional.ofNullable(jsonObject.getString("payType"))
.orElseThrow(() -> new MsgException("支付方式不能为空!"));
Optional.ofNullable(jsonObject.getString("userId"))
.orElseThrow(() -> new MsgException("付款用户不能为空!"));
}
Optional.ofNullable(jsonObject.getString("subject"))
.orElseThrow(() -> new MsgException("订单标题不能为空!"));
return storeInfo;
}
private String checkMercOrder(TbPlussMerchantStore store, JSONObject jsonObject) {
List<TbPlussMerchantOrder> list = tbPlussMerchantOrderMapper.selectByMercorderno(jsonObject.getString("mercOrderNo"));
if (ObjectUtil.isNotEmpty(list)&&list.size()>0) {
TbPlussMerchantOrder order = list.get(0);
if(StringUtil.isNotEmpty(order.getPaydata())){
StringBuilder payData = new StringBuilder(order.getPaydata());
payData.insert(payData.length()-1,",\"orderNumber\":"+"\""+order.getOrdernumber()+"\"");
return payData.toString();
}
throw new MsgException("订单号重复!");
}
if ("0".equals(store.getStatus())) {
throw new MsgException("店铺已经打烊!");
}
if ("2".equals(store.getStatus())) {
throw new MsgException("店铺已被禁用!");
}
return null;
}
}

View File

@ -0,0 +1,82 @@
package com.chaozhanggui.system.order.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.common.system.config.ResultGenerator;
import com.chaozhanggui.dao.system.dao.TbPlussSubMercCodeYsMapper;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantStore;
import com.chaozhanggui.dao.system.entity.TbPlussSubMercCodeYs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class OrderService {
@Autowired
OrderParamCheck orderParamCheck;
@Autowired
TbPlussSubMercCodeYsMapper tbPlussSubMercCodeYsMapper;
public JSONObject pay(String json,String ip){
Optional.ofNullable(json).orElseThrow(() -> new MsgException("请求参数为空"));
JSONObject jsonObject;
try {
jsonObject = JSONObject.parseObject(json);
} catch (JSONException e) {
throw new MsgException("JSON字符串有误请检查!");
}
String res = orderParamCheck.currencyParamsCheck(jsonObject);
if(ObjectUtil.isNotEmpty(res)){
return ResultGenerator.genSuccessJsonResult("处理成功",JSONObject.parseObject(res));
}
if(ObjectUtil.isEmpty(ip)){
ip = jsonObject.getString("ip");
}
jsonObject.put("ip",ip);
String cityName = jsonObject.getString("cityName");
String provinceName = jsonObject.getString("provinceName");
if(ObjectUtil.isNotEmpty(cityName)){
jsonObject.put("ipAddress",provinceName + "-" + cityName);
TbPlussSubMercCodeYs ysCode = tbPlussSubMercCodeYsMapper.selectByCityName(cityName);
if(ysCode != null){
jsonObject.put("pCode",ysCode.getPcode());
jsonObject.put("cCode",ysCode.getCode());
}
}else{
if(ObjectUtil.isNotEmpty(ip)){
DescribeIpv4LocationResponse location = ipLocationService.getLocation(ip);
if(location != null && StringUtil.isNotEmpty(location.getCity())){
SubMercCodeYs ysCode = subMercCodeYsMapper.getSubMercCodeYsByCity(location.getCity());
if(ysCode != null){
jsonObject.put("pCode",ysCode.getPCode());
jsonObject.put("cCode",ysCode.getCode());
}
jsonObject.put("ipAddress",location.getProvince() + "-" + location.getCity());
}else{
String ipAddress = IpUtils.getIpLoactionAddress(location);
jsonObject.put("ipAddress",ipAddress);
}
}
}
switch (jsonObject.getString("method")) {
case "trans_query":
return tradeQuery(jsonObject);
default:
return tradePay(jsonObject);
}
}
}

View File

@ -19,6 +19,7 @@
<module>oss-service</module>
<module>admin</module>
<module>merchant-service-api</module>
<module>order-service</module>
</modules>