wangtuohang@126.com hace 1 mes
padre
commit
cea7abb9b4

+ 85 - 17
src/main/java/org/springblade/modules/spzf/payInfo/controller/PayInfoController.java

@@ -34,6 +34,8 @@ import com.alipay.api.internal.util.AlipayEncrypt;
 import com.alipay.api.internal.util.AlipaySignature;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -42,6 +44,8 @@ import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.Valid;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springblade.common.utils.AsciiOrderUtil;
+import org.springblade.common.utils.MD5Util;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.excel.util.ExcelUtil;
 import org.springblade.core.http.util.HttpUtil;
@@ -57,15 +61,20 @@ import org.springblade.modules.spzf.payInfo.excel.PayInfoExcel;
 import org.springblade.modules.spzf.payInfo.pojo.entity.PayInfoEntity;
 import org.springblade.modules.spzf.payInfo.pojo.vo.PayInfoVO;
 import org.springblade.modules.spzf.payInfo.pojo.vo.wx.PhoneNumberVO;
+import org.springblade.modules.spzf.payInfo.pojo.vo.yszf.JsapiVO;
 import org.springblade.modules.spzf.payInfo.service.IPayInfoService;
 import org.springblade.modules.spzf.payInfo.wrapper.PayInfoWrapper;
 import org.springblade.modules.system.pojo.entity.User;
 import org.springblade.modules.system.service.IUserService;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static org.springblade.common.utils.SignUtil.getPrivateKey;
+import static org.springblade.common.utils.SignUtil.sign;
+
 /**
  * 付款记录 控制器
  *
@@ -85,16 +94,17 @@ public class PayInfoController extends BladeController {
 
 	private final String secret = "5ce4a147f3cfe7b6eb4953b41109ce66";
 
+	private final String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCc1mku1mtfTc1vZM9z3TkRMZ9SaKP+6MdoQhjDHB9vJUOuG2Jnegej4gtzcm8MVYomV1azJMtCbPq4PN9aHegH13JthvrUPR3nAKp8AUp9Fh47ded//snNyAf7C7o8xKN5e7n89ROwacCAL2QDno76ngXzQQVj1TxY9pBdekZ03ezuDk1sv/u4FBlW8kRyaVdqyl4FdvP+EEljDe8gGxRikLyb3cK1B6G7w2BXgM/svft5SOoiqStx2XvgHRrFRB5w96TdoKNH9yxHU2clMJiz+5cej1VL6OHZspuY3cnPyJtyS+weYjDT+COLLBUe9UwbOV15DXDNpBLd34W4GiqtAgMBAAECggEAYaVwmVOwSAblp7wJGScb16OggStbJ2MAe93jEt7Yh1eZGrY7/xbP2O3smTUfBHvhZlusRB7dWf8F3l0v5iiGhRNTT/PhCPEARAl7G3emS9jQe869kkgslq06ose7bQg0i3dH5cEkQAqnameXClXWyRxHshrCY1SonO7uFPUDFtD2Z9GHu6dOWkOHfX7UETHV5/NTSqvner5M2YNsV/5To87zrmaeeNyvu91JgJSYofTD8IcMyhxcswxB9F3ECP7nulLDdCV+9mvE9zO0i4mPBxYb++87J0pu35TN9OY+gpiCK3Ed0gDqvvkTiCQEFu6y7OiqsQwy03CE5hAwWZR2YQKBgQDdb6e7+FWJSr9fIknfvZPPtKmbEkMHP1RYnVo3pmuVm14Z3UmostiSBRPMfVjeOX0N82SONM9P+1v9SDgSK3pL8rlk9Hx6D5KI7uj2IMtTVt00pO31KtxDLmXfgapDbWHK1RGEn1PDrnKYy5yOKJ8n0Wgp4lVEPIBN6uIud0A9iQKBgQC1UXdhEXFETyqEYWb9OnWbBjiVIw3D2/qW5c+WQGsHYdMEImC/0oTWIH9fKd4Azf26JjZ9nQvs5VcijJP6BXbGPqir5NgGVkwCj33PoNg4dDgIVE4BYaSp//7B6jCi5QiRTzCSOmUSkZ5L1Kz4SNEDe9r0MpLhxrsAzmR9aEJ/BQKBgHI71Ks63F2cSwd39+ZNtYA0cj7Gd/+4IvooCs+kseGXKj9rkkFOKj2CEwmuLHdP7vyQcHKQOdbIFFegtxRgi5G8oPm8yq5pdC3iGhpHJr1SlYFACGYu+zxJJlLcYIqyVf2+V3A0hZDwYLwEZjpMKHbxJ6xbz6MJFyObJZ3U9TYJAoGANXoGjJF5Z501u/+CQZN5VjSagZnqGGcL3G+BLx5msrGua9y7zjeHyCOjjWyqtnAKsllM3vVvq/nkHiN6DVaJNmUKmFARSqUvG944TAFzZAsa75H1w8CJsT34ZDbvC0wjn7/MYoRohPZ/ynu6XCwVwUJJTJaR7ZcQVmeJCdezLQUCgYEAszix6V9oL80Clb1nMwIly6I78+pcFKyk82yXxvySb6XPJvgoasbz9xYIeKlPyy6r8Aj/ujz5GVtDtkE6n6bsjekCdnUKUY3uTvFAX+YGQkuZnaPoisELJFI2Hal22tNnJyCOYh//AGAiHYpHNUKD4hsKBb45MhK1xwvTHpuLkdc=";
+
 	private final IUserService userService;
 
 	/**
 	 * 微信登录
-	 * params js_code code
+	 * params js_code
 	 */
 	@GetMapping("/wxLogin")
 	public R wxLogin(@RequestParam Map<String, Object> params) {
 		log.info("参数js_code打印:" + params.get("js_code").toString());
-		log.info("参数code打印:" + params.get("code").toString());
 		// 小程序登录接口 参数:appid/secret/js_code/grant_type
 		params.put("appid", appid);
 		params.put("secret", secret);
@@ -110,26 +120,52 @@ public class PayInfoController extends BladeController {
 		queryWrapper.eq("account", openid);
 		User user = userService.getOne(queryWrapper);
 		if (null != user) {
-			return R.data(user.getPhone());
+			return R.data(user, "1");
 		} else {
-			// 获取接口调用凭据(access_token) 参数:grant_type/appid/secret
-			params.put("grant_type", "client_credential");
-			JSONObject getAccessTokenJsonObject = JSONObject.parseObject(HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", params));
-			String accessToken = getAccessTokenJsonObject.getString("access_token");
-			// 获取手机号 参数:grant_type
-			PhoneNumberVO phoneNumberVO = JSONObject.parseObject(HttpUtil.postJson("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken, JSONObject.toJSONString(params.get("code"))), PhoneNumberVO.class);
-			// 注册到blade_user
-			User newUser = new User();
-			newUser.setAccount(openid);
-			newUser.setPhone(phoneNumberVO.getPhone_info().getPhoneNumber());
-			newUser.setCode("wx");
-			newUser.setPassword("Xwkj2024@ 确认加密后的密码");
-			userService.submit(newUser);
-			return R.data(phoneNumberVO.getPhone_info().getPhoneNumber());
+			user = new User();
+			user.setAccount(openid);
+			return R.data(user, "0");
 		}
 	}
 
 	/**
+	 * 微信获取手机号
+	 * params code openid
+	 */
+	@GetMapping("/wxGetPhoneNumber")
+	public R wxGetPhoneNumber(@RequestParam Map<String, Object> params) {
+		// 获取接口调用凭据(access_token) 参数:grant_type/appid/secret
+		params.put("appid", appid);
+		params.put("secret", secret);
+		params.put("grant_type", "client_credential");
+		JSONObject getAccessTokenJsonObject = JSONObject.parseObject(HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", params));
+		String accessToken = getAccessTokenJsonObject.getString("access_token");
+		// 获取手机号 参数:grant_type
+		Map<String, Object> params1 = new HashMap<>();
+		params1.put("code", params.get("code"));
+		PhoneNumberVO phoneNumberVO = JSONObject.parseObject(HttpUtil.postJson("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken, JSONObject.toJSONString(params1)), PhoneNumberVO.class);
+		// 看这个手机号在blade_user中有没有(白名单)
+		QueryWrapper<User> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("phone", phoneNumberVO.getPhone_info().getPhoneNumber());
+		User user = userService.getOne(queryWrapper);
+		if (null != user) {
+			user.setAccount(params.get("openid").toString());
+			user.setCode("1");
+			user.setPassword("d28827d68287a18ed058014d6858a1af2da7dddf");
+			userService.updateById(user);
+			return R.data(user);
+		}
+		// 注册到blade_user
+		User newUser = new User();
+		newUser.setAccount(params.get("openid").toString());
+		newUser.setPhone(phoneNumberVO.getPhone_info().getPhoneNumber());
+		newUser.setCode("wx");
+		newUser.setPassword("d28827d68287a18ed058014d6858a1af2da7dddf");
+		userService.submit(newUser);
+		return R.data(newUser);
+	}
+
+	/**
 	 * 支付宝 验签与解密处理
 	 * params js_code code
 	 */
@@ -175,6 +211,38 @@ public class PayInfoController extends BladeController {
 	}
 
 	/**
+	 * 付款
+	 */
+	@GetMapping("/jsapi")
+	public R jsapi(@RequestParam Map<String, Object> params) throws Exception {
+		JsapiVO jsapiVO = new JsapiVO();
+		jsapiVO.getReqBody().getReqOrderInfo().setOrgTrace(jsapiVO.getReqBody().getReqInfo().getMchtCode() + jsapiVO.getReqHeader().getTransTime());
+
+		ObjectMapper mapper = new ObjectMapper();
+		// 注册自定义的BeanSerializerModifier
+		SimpleModule module = new SimpleModule();
+		module.setSerializerModifier(new AsciiOrderUtil());
+		mapper.registerModule(module);
+
+		String reqHeaderJsonString = mapper.writeValueAsString(jsapiVO.getReqHeader());
+		log.info("排序后的 reqHeader (未压缩字符串前) == " + reqHeaderJsonString);
+		String reqBodyJsonString = mapper.writeValueAsString(jsapiVO.getReqBody());
+		log.info("排序后的 reqBody (未压缩字符串前) == " + reqBodyJsonString);
+		String md5 = MD5Util.getMD5Hash(reqBodyJsonString);
+		log.info("MD5 == " + md5);
+		String sign = reqHeaderJsonString + md5;
+		log.info("待签名字符串 == " + md5);
+		String reqSign = sign(sign.getBytes("utf-8"), getPrivateKey(privateKey), "SHA256withRSA");
+		log.info("计算出reqSign的值是 " + reqSign);
+		jsapiVO.setReqSign(reqSign);
+		System.out.println(JSONObject.toJSONString(jsapiVO));
+
+
+		String result = HttpUtil.postJson("http://106.14.187.117:31110/yqt/trade/jsapi", JSONObject.toJSONString(jsapiVO));
+		return R.data(result);
+	}
+
+	/**
 	 * 付款记录 详情
 	 */
 	@GetMapping("/detail")

+ 20 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/AliBizParamVO.java

@@ -0,0 +1,20 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class AliBizParamVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private String buyerId;
+
+}

+ 25 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/IdentityVO.java

@@ -0,0 +1,25 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class IdentityVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private String name;
+
+	private String certType;
+
+	private String certNo;
+
+	private String dgtlEnvlp;
+}

+ 3 - 1
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/JsapiVO.java

@@ -15,8 +15,10 @@ public class JsapiVO {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
-	private ReqHeaderVO reqHeader;
+	private ReqHeaderVO reqHeader = new ReqHeaderVO();
 
 	private String reqSign;
 
+	private ReqBodyVO reqBody = new ReqBodyVO();
+
 }

+ 5 - 3
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/PayInfoVO.java

@@ -3,6 +3,8 @@ package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
 import lombok.Data;
 
 import java.io.Serial;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 
 /**
  * 微信获取手机号 视图实体类
@@ -15,10 +17,10 @@ public class PayInfoVO {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
-	private String productCode;
+	private String productCode = "1"; // 产品代码
 
-	private String payType;
+	private String payType = "WeChatJsapi"; // 支付方式
 
-	private String transDate;
+	private String transDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); // 业务日期 YYYYMMDD
 
 }

+ 33 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/ReqBodyVO.java

@@ -0,0 +1,33 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class ReqBodyVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private ReqInfoVO reqInfo =  new ReqInfoVO();
+
+	private PayInfoVO payInfo =  new PayInfoVO();
+
+	private ReqOrderInfoVO reqOrderInfo =  new ReqOrderInfoVO();
+
+	private RiskDataVO riskData =  new RiskDataVO();
+
+//	private AliBizParamVO aliBizParam;
+
+	private WxBizParamVO wxBizParam = new WxBizParamVO();
+
+	private SettleParamInfoVO settleParamInfo = new SettleParamInfoVO();
+
+
+}

+ 4 - 2
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/ReqHeaderVO.java

@@ -3,6 +3,8 @@ package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
 import lombok.Data;
 
 import java.io.Serial;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 
 /**
  * 微信获取手机号 视图实体类
@@ -15,8 +17,8 @@ public class ReqHeaderVO {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
-	private String transTime;
+	private String transTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
 
-	private String reqId;
+	private String reqId = "531000023045074"; // 密钥Id
 
 }

+ 1 - 1
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/ReqInfoVO.java

@@ -15,6 +15,6 @@ public class ReqInfoVO {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
-	private String mchtCode;
+	private String mchtCode = "531000023045074"; // 合作商户号,易生提供
 
 }

+ 5 - 4
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/ReqOrderInfoVO.java

@@ -15,12 +15,13 @@ public class ReqOrderInfoVO {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
-	private String orgTrace;
+	private String orgTrace = "95405082114074348753"; // 商户订单号
 
-	private String transAmount;
+	private String transAmount = "1"; // 订单金额
 
-	private String orderSub;
+	private String orderSub = "jkkkkkkkkkkkkk"; // 订单标题
+
+	private String backUrl = "https://www.baidu.com"; // 异步通知地址
 
-	private String backUrl;
 
 }

+ 21 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/RiskDataVO.java

@@ -0,0 +1,21 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class RiskDataVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private String customerIp = "127.1.1.1"; // 用户ip
+
+	private TerminalInfoVO terminalInfo = new TerminalInfoVO(); // 终端信息
+}

+ 24 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/SettleParamInfoVO.java

@@ -0,0 +1,24 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class SettleParamInfoVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private String delaySettleFlag = "0"; // 0: 非延时结算,由patnerSettleFlag字段结算
+
+	private String patnerSettleFlag = "0"; // 0: 非D0交易,即按进件商户开通功能结算周期结算
+
+	private String splitSettleFlag = "0"; // 0:非分账交易
+
+}

+ 22 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/TerminalInfoVO.java

@@ -0,0 +1,22 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class TerminalInfoVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private String location = "+37.12/-121.213"; // 终端实时经纬度信息
+
+	private String terminalIp = "192.168.2.1"; // 终端IP
+
+}

+ 22 - 0
src/main/java/org/springblade/modules/spzf/payInfo/pojo/vo/yszf/WxBizParamVO.java

@@ -0,0 +1,22 @@
+package org.springblade.modules.spzf.payInfo.pojo.vo.yszf;
+
+import lombok.Data;
+
+import java.io.Serial;
+
+/**
+ * 微信获取手机号 视图实体类
+ *
+ * @author wth
+ * @since 2024-12-06
+ */
+@Data
+public class WxBizParamVO {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	private String subAppid = "wx83dda3fdc5d8a8e0"; // 微信分配的子商户公众账号ID
+
+	private String subOpenId = "o5VRZ5AxnUZT5hjeoooNwBksKHLw"; // 用户子标识
+
+}