|
@@ -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")
|