From b0115ff5564f4080d16d57a547dab0ee9c66ba10 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期四, 13 六月 2024 22:34:37 +0800
Subject: [PATCH] 2024-06-13 朱宝民 微信支付接口
---
/dev/null | 91 -----------
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java | 21 --
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeOpenIdMapper.xml | 1
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/PayHelper.java | 1
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/NotifyResource.java | 40 +++++
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/OrderNotify.java | 60 +++---
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java | 190 +++++++++--------------
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/virtualCard/VirtualCardSv.java | 9 +
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PayInfo.java | 2
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/DtoOrder.java | 6
10 files changed, 160 insertions(+), 261 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeWebchatLogonStateMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeWebchatLogonStateMapper.java
deleted file mode 100644
index 4837b8f..0000000
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeWebchatLogonStateMapper.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.dy.pipIrrGlobal.daoSe;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * @author ZhuBaoMin
- * @date 2024-02-22 17:31
- * @LastEditTime 2024-02-22 17:31
- * @Description
- */
-
-@Mapper
-public interface SeWebchatLogonStateMapper extends BaseMapper<SeWebchatLogonState> {
- int deleteByPrimaryKey(Long id);
-
- int insert(SeWebchatLogonState record);
-
- int insertSelective(SeWebchatLogonState record);
-
- SeWebchatLogonState selectByPrimaryKey(Long id);
-
- int updateByPrimaryKeySelective(SeWebchatLogonState record);
-
- int updateByPrimaryKey(SeWebchatLogonState record);
-}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeWebchatLogonState.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeWebchatLogonState.java
deleted file mode 100644
index b8c01be..0000000
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeWebchatLogonState.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.dy.pipIrrGlobal.pojoSe;
-
-import com.alibaba.fastjson2.annotation.JSONField;
-import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.dy.common.po.BaseEntity;
-import io.swagger.v3.oas.annotations.media.Schema;
-import jakarta.validation.constraints.NotBlank;
-import lombok.*;
-
-import java.util.Date;
-
-/**
- * @author ZhuBaoMin
- * @date 2024-02-22 17:31
- * @LastEditTime 2024-02-22 17:31
- * @Description
- */
-
-@TableName(value="se_webchat_logon_state", autoResultMap = true)
-@Data
-@Builder
-@ToString
-@NoArgsConstructor
-@AllArgsConstructor
-@Schema(name = "鐧诲綍鎬佽褰曞疄浣�")
-public class SeWebchatLogonState implements BaseEntity {
- public static final long serialVersionUID = 202402221735001L;
-
- /**
- * 涓婚敭
- */
- @JSONField(serializeUsing= ObjectWriterImplToString.class)
- @TableId(type = IdType.INPUT)
- @Schema(description = "瀹炰綋id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
- private Long id;
-
- /**
- * 鐢ㄦ埛鍞竴鏍囪瘑
- */
- @Schema(description = "鐢ㄦ埛鍞竴鏍囪瘑", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
- @NotBlank(message = "鐢ㄦ埛鍞竴鏍囪瘑涓嶈兘涓虹┖")
- private String openId;
-
- /**
- * 浼氳瘽瀵嗛挜
- */
- @Schema(description = "浼氳瘽瀵嗛挜", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
- @NotBlank(message = "浼氳瘽瀵嗛挜涓嶈兘涓虹┖")
- private String sessionKey;
-
- /**
- * 鍒涘缓鏃堕棿
- */
- @Schema(description = "鍒涘缓鏃堕棿", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
- @NotBlank(message = "鍒涘缓鏃堕棿涓嶈兘涓虹┖")
- private Date createTime;
-}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeOpenIdMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeOpenIdMapper.xml
index def611f..e6d2506 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeOpenIdMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeOpenIdMapper.xml
@@ -99,4 +99,5 @@
create_time = #{createTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
+
</mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeWebchatLogonStateMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeWebchatLogonStateMapper.xml
deleted file mode 100644
index 973ab13..0000000
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeWebchatLogonStateMapper.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.dy.pipIrrGlobal.daoSe.SeWebchatLogonStateMapper">
- <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState">
- <!--@mbg.generated-->
- <!--@Table se_webchat_logon_state-->
- <id column="id" jdbcType="BIGINT" property="id" />
- <result column="open_id" jdbcType="VARCHAR" property="openId" />
- <result column="session_key" jdbcType="VARCHAR" property="sessionKey" />
- <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
- </resultMap>
- <sql id="Base_Column_List">
- <!--@mbg.generated-->
- id, open_id, session_key, create_time
- </sql>
- <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
- <!--@mbg.generated-->
- select
- <include refid="Base_Column_List" />
- from se_webchat_logon_state
- where id = #{id,jdbcType=BIGINT}
- </select>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
- <!--@mbg.generated-->
- delete from se_webchat_logon_state
- where id = #{id,jdbcType=BIGINT}
- </delete>
- <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState">
- <!--@mbg.generated-->
- insert into se_webchat_logon_state (id, open_id, session_key,
- create_time)
- values (#{id,jdbcType=BIGINT}, #{openId,jdbcType=VARCHAR}, #{sessionKey,jdbcType=VARCHAR},
- #{createTime,jdbcType=TIMESTAMP})
- </insert>
- <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState">
- <!--@mbg.generated-->
- insert into se_webchat_logon_state
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">
- id,
- </if>
- <if test="openId != null">
- open_id,
- </if>
- <if test="sessionKey != null">
- session_key,
- </if>
- <if test="createTime != null">
- create_time,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">
- #{id,jdbcType=BIGINT},
- </if>
- <if test="openId != null">
- #{openId,jdbcType=VARCHAR},
- </if>
- <if test="sessionKey != null">
- #{sessionKey,jdbcType=VARCHAR},
- </if>
- <if test="createTime != null">
- #{createTime,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState">
- <!--@mbg.generated-->
- update se_webchat_logon_state
- <set>
- <if test="openId != null">
- open_id = #{openId,jdbcType=VARCHAR},
- </if>
- <if test="sessionKey != null">
- session_key = #{sessionKey,jdbcType=VARCHAR},
- </if>
- <if test="createTime != null">
- create_time = #{createTime,jdbcType=TIMESTAMP},
- </if>
- </set>
- where id = #{id,jdbcType=BIGINT}
- </update>
- <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState">
- <!--@mbg.generated-->
- update se_webchat_logon_state
- set open_id = #{openId,jdbcType=VARCHAR},
- session_key = #{sessionKey,jdbcType=VARCHAR},
- create_time = #{createTime,jdbcType=TIMESTAMP}
- where id = #{id,jdbcType=BIGINT}
- </update>
-</mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/PayHelper.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/PayHelper.java
index e90474a..6385700 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/PayHelper.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/PayHelper.java
@@ -269,6 +269,7 @@
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", header);
headers.put("Accept", "application/json");
+ //headers.put("User-Agent", "https://zh.wikipedia.org/wiki/User_agent");
JSONObject job_result = restTemplateUtil.getHeaders(PayInfo.certificates,null, headers);
JSONObject job_headers = job_result.getJSONObject("headers");
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/virtualCard/VirtualCardSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/virtualCard/VirtualCardSv.java
index e478388..832e9da 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/virtualCard/VirtualCardSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/virtualCard/VirtualCardSv.java
@@ -155,6 +155,15 @@
}
/**
+ * 鏍规嵁璁㈠崟鍙疯幏鍙栬櫄鎷熷崱鍏呭�煎璞�
+ * @param orderNumber
+ * @return
+ */
+ public SeVcRecharge getVCRechargeByorderNumber(String orderNumber) {
+ return seVcRechargeMapper.getVCRechargeByorderNumber(orderNumber);
+ }
+
+ /**
* 淇敼铏氭嫙鍗″厖鍊艰褰�
* 寰俊鏀粯閫氱煡鍚庯細
* 1. 鏇存柊鍏呭�艰〃锛氬厖鍊煎悗浣欓銆佹敮浠樺畬鎴愭椂闂淬�佽鍗曠姸鎬�
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PayInfo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PayInfo.java
index 4e96448..a91afb1 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PayInfo.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PayInfo.java
@@ -42,7 +42,7 @@
* 鏀粯缁撴灉閫氱煡API
*/
//public static String notifyUrl = "https://www.muxiaobao.com/api/Payment/OrderNotify";
- public static String notifyUrl = "https://44978f7456.imdo.co/webchat/payment/orderNotify";
+ public static String notifyUrl = "https://44978f7456.imdo.co/sell/payment/orderNotify";
/*
* 鏌ヨ璁㈠崟API
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java
index 48e0a35..2d237fa 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java
@@ -1,5 +1,6 @@
package com.dy.pipIrrSell.wechatpay;
+import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
@@ -17,8 +18,8 @@
import com.dy.pipIrrSell.virtualCard.enums.LastOperateENUM;
import com.dy.pipIrrSell.virtualCard.enums.RefundItemStateENUM;
import com.dy.pipIrrSell.wallet.enums.RefundStatusENUM;
-import com.dy.pipIrrSell.wechatpay.dto.Code2Session;
import com.dy.pipIrrSell.wechatpay.dto.DtoOrder;
+import com.dy.pipIrrSell.wechatpay.dto.NotifyResource;
import com.dy.pipIrrSell.wechatpay.dto.OrderNotify;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
@@ -26,6 +27,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
@@ -37,6 +39,7 @@
import org.springframework.web.bind.annotation.*;
import javax.crypto.NoSuchPaddingException;
+import java.io.BufferedReader;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
@@ -80,60 +83,6 @@
// 骞冲彴璇佷功鍏挜
private final Map CERTIFICATE_MAP = new HashMap();
-
- /**
- * 鐧诲綍鍑瘉鏍¢獙
- * @param code2Session 鐧诲綍鍑瘉鏍¢獙浼犲叆瀵硅薄
- * @param bindingResult
- * @return
- * @throws Exception
- */
- @Operation(summary = "鐧诲綍鍑瘉鏍¢獙", description = "鐧诲綍鍑瘉鏍¢獙")
- @ApiResponses(value = {
- @ApiResponse(
- responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- schema = @Schema(implementation = Boolean.class))}
- )
- })
- @PostMapping(path = "getSessionId")
- @Transactional(rollbackFor = Exception.class)
- @SsoAop()
- public BaseResponse<Boolean> getSessionId(@RequestBody @Valid Code2Session code2Session, BindingResult bindingResult) throws Exception {
- if(bindingResult != null && bindingResult.hasErrors()){
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
-
- Map<String, Object> queryParams = new HashMap<>();
- queryParams.put("appid", appid);
- queryParams.put("secret", code2Session.getSecret());
- queryParams.put("js_code", code2Session.getJs_code());
- queryParams.put("grant_type", grantType);
- Map<String, String> headerParams = new HashMap<>();
- JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
-
- if(job.getLong("errcode") != null && job.getLong("errcode") >= -1) {
- return BaseResponseUtils.buildFail("鐧诲綍鍑瘉鏍¢獙澶辫触");
- }
-
- String openid = job.getString("openid");
- String sessionKey = job.getString("session_key");
-
- // 娣诲姞鐧诲綍鎬佽褰�
- SeWebchatLogonState po = new SeWebchatLogonState();
- po.setOpenId(openid);
- po.setSessionKey(sessionKey);
- Date createTime = new Date();
- po.setCreateTime(createTime);
- Long id = paymentSv.insert(po);
- if(id == null || id <= 0) {
- return BaseResponseUtils.buildFail("鐧诲綍鎬佽褰曟坊鍔犲け璐�");
- }
- String SessionId = String.valueOf(id);
-
- return BaseResponseUtils.buildSuccess(SessionId) ;
- }
/**
* 涓嬭浇寰俊鏀粯骞冲彴璇佷功 娴嬭瘯瀹屽簾闄�
@@ -203,14 +152,12 @@
if(bindingResult != null && bindingResult.hasErrors()){
return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
}
- // 鎺ユ敹鍙傛暟锛氱櫥褰曟�両D銆佸啘鎴稩D銆佽櫄鎷熷崱ID銆佸厖鍊奸噾棰�
+ // 鎺ユ敹鍙傛暟锛氱櫥褰曟�両D銆佽櫄鎷熷崱ID銆佸厖鍊奸噾棰濓紙鍒嗭級
Long sessionId = order.getSessionId();
- Long virtualId = order.getVirtualId();
+ Long virtualId = order.getVcId();
Integer rechargeAmount = order.getRechargeAmount();
String prepayId = "";
- //SeWebchatLogonState po = paymentSv.selectOne(Long.parseLong(sessionId));
- //String openid = po.getOpenId();
SeOpenId po = paymentSv.selectOne(sessionId);
String openid = po.getOpenId();
@@ -245,7 +192,7 @@
//璁㈠崟閲戦
JSONObject job_amount = new JSONObject();
- job_amount.put("total", 1);
+ job_amount.put("total", rechargeAmount);
job_amount.put("currency", "CNY");
job_body.put("amount", job_amount);
@@ -278,9 +225,47 @@
}
/**
+ * 鍐嶆绛惧悕
+ * @param prepayId 棰勬敮浠樹氦鏄撲細璇濇爣璇�
+ * @return 灏忕▼搴忚皟璧锋敮浠樺弬鏁�
+ * @throws Exception
+ */
+ @Operation(summary = "鍐嶆绛惧悕", description = "鍐嶆绛惧悕")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Boolean.class))}
+ )
+ })
+ @GetMapping(path = "/signAgain")
+ @Transactional(rollbackFor = Exception.class)
+ @SsoAop()
+ public BaseResponse<JSONObject> signAgain(@RequestParam("prepayId") String prepayId) throws Exception {
+
+ // 鑾峰彇闅忔満涓插拰鏃堕棿鎴筹紝鏀惧湪姝ゅ浠ヤ繚璇�
+ String appid = PayInfo.appid;
+ String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
+ String nonceStr = payHelper.generateRandomString();
+ String pkg = "prepay_id=" + prepayId;
+ String message = payHelper.buildMessage_signAgain(appid, timeStamp, nonceStr, pkg);
+ String paySign = payHelper.sign(message.getBytes("utf-8"), privateCertFileName);
+
+ JSONObject job_result = new JSONObject();
+ job_result.put("timeStamp", timeStamp);
+ job_result.put("nonceStr", nonceStr);
+ job_result.put("package", pkg);
+ job_result.put("signType", signType);
+ job_result.put("paySign", paySign);
+
+ return BaseResponseUtils.buildSuccess(job_result) ;
+ }
+
+ /**
* 鏀粯閫氱煡/閫�娆剧粨鏋滈�氱煡
* @param headers
- * @param orderNotify
+ * @param request
* @param response
* @return
* @throws IOException
@@ -298,12 +283,12 @@
@PostMapping(path = "orderNotify", consumes = MediaType.APPLICATION_JSON_VALUE)
@Transactional(rollbackFor = Exception.class)
@SsoAop()
- public JSONObject orderNotify(@RequestHeader HttpHeaders headers, @RequestBody OrderNotify orderNotify, HttpServletResponse response) throws IOException, GeneralSecurityException {
+ public JSONObject orderNotify(@RequestHeader HttpHeaders headers, HttpServletRequest request, HttpServletResponse response) throws IOException, GeneralSecurityException {
JSONObject result = new JSONObject();
/**
* 1.楠岀澶勭悊
- * 浠巋eader涓彇鍑�4涓瓙鍙傛暟锛屽悓鏃跺彇鍑篵ody
+ * 浠巋eader涓彇鍑�4涓瓙鍙傛暟
* 楠屾椂闂村樊锛岃秴杩�5鍒嗛挓鐨勪笉澶勭悊
* 楠岃瘉绛惧悕
* 楠岃瘉涔﹀簭鍒楀彿锛屽繀椤讳笌鏌愪竴涓瘉涔︾殑搴忓垪鍙蜂竴鑷�
@@ -312,7 +297,18 @@
String wechatpaySerial = String.valueOf(headers.get("Wechatpay-Serial").get(0));
String wechatpaySignature = String.valueOf(headers.get("Wechatpay-Signature").get(0));
String wechatpayTimestamp = String.valueOf(headers.get("Wechatpay-Timestamp").get(0));
- String bodyStr = JSONObject.toJSONString(orderNotify);
+
+ // 鑾峰彇body鍐呭
+ BufferedReader reader = request.getReader();
+ StringBuilder stringBuilder = new StringBuilder();
+ String line;
+ while ((line = reader.readLine()) != null) {
+ stringBuilder.append(line);
+ }
+ String bodyStr = stringBuilder.toString();
+
+ // body杞璞�
+ OrderNotify orderNotify = JSON.parseObject(bodyStr, OrderNotify.class);
// 楠屾椂闂存埑锛屾椂闂村樊澶т簬5鍒嗛挓鐨勬嫆缁�
Long timeDiff = (System.currentTimeMillis() / 1000 - Long.parseLong(wechatpayTimestamp))/60;
@@ -348,10 +344,7 @@
return result;
}
- /**
- * 瑙e瘑澶勭悊
- * 1
- */
+ // 瑙e瘑澶勭悊
String eventType = orderNotify.getEvent_type();
if(eventType != null && eventType.equals("TRANSACTION.SUCCESS")) {
@@ -361,7 +354,7 @@
* 鍙栧嚭閫氱煡鏁版嵁瀵硅薄锛岀户鑰屽彇鍑鸿В瀵嗘墍闇�鐨刟ssociatedData鍜宯once锛屼互鍙婂瘑鏂嘽iphertext
* 瑙e瘑ciphertext寰楀埌
*/
- OrderNotify.NotifyResource notifyResource = orderNotify.getResource();
+ NotifyResource notifyResource = orderNotify.getResource();
String associatedData = notifyResource.getAssociated_data();
String nonce = notifyResource.getNonce();
String ciphertext = notifyResource.getCiphertext();
@@ -369,19 +362,22 @@
String resource = AesUtil.decryptToString(PayInfo.key.getBytes("utf-8"), associatedData.getBytes("utf-8"), nonce.getBytes("utf-8"), ciphertext);
JSONObject job_resource = JSONObject.parseObject(resource);
- // 瑙e瘑鍚庡彇鍑猴細鍟嗘埛璁㈠崟鍛樸�佸井淇℃敮浠樿鍗曞彿銆佷氦鏄撶姸鎬併�佹敮浠樺畬鎴愭椂闂�
+ // 瑙e瘑鍚庡彇鍑猴細鍟嗘埛璁㈠崟鍙枫�佸井淇℃敮浠樿鍗曞彿銆佷氦鏄撶姸鎬併�佹敮浠樺畬鎴愭椂闂�
String out_trade_no = job_resource.getString("out_trade_no");
String transaction_id = job_resource.getString("transaction_id");
String trade_state = job_resource.getString("trade_state");
Date success_time = job_resource.getDate("success_time");
- // 鏇存柊铏氭嫙鍗¤〃鍙婂厖鍊艰〃鍝嶅簲瀛楁
- BaseResponse result_ = virtualCardSv.updateVCRecharge(out_trade_no, success_time);
- if(!result_.getCode().equals("0001")) {
- response.setStatus(500);
- result.put("code", "FAIL");
- result.put("message", "澶辫触");
- return result;
+ // 濡傛灉褰撳墠璁㈠崟鐘舵�佷负鏈敮浠樼姸鎬侊紝鍒欐洿鏂拌櫄鎷熷崱琛ㄥ強鍏呭�艰〃鍝嶅簲瀛楁
+ SeVcRecharge seVcRecharge = virtualCardSv.getVCRechargeByorderNumber(out_trade_no);
+ if(seVcRecharge != null && seVcRecharge.getOrderState() == 1) {
+ BaseResponse result_ = virtualCardSv.updateVCRecharge(out_trade_no, success_time);
+ if(!result_.getCode().equals("0001")) {
+ response.setStatus(500);
+ result.put("code", "FAIL");
+ result.put("message", "澶辫触");
+ return result;
+ }
}
} else if(eventType != null && eventType.equals("REFUND.SUCCESS")) {
// 閫�娆炬垚鍔熷悗鍥炶皟
@@ -390,7 +386,7 @@
* 鍙栧嚭閫氱煡鏁版嵁瀵硅薄锛岀户鑰屽彇鍑鸿В瀵嗘墍闇�鐨刟ssociatedData鍜宯once锛屼互鍙婂瘑鏂嘽iphertext
* 瑙e瘑ciphertext寰楀埌
*/
- OrderNotify.NotifyResource notifyResource = orderNotify.getResource();
+ NotifyResource notifyResource = orderNotify.getResource();
String associatedData = notifyResource.getAssociated_data();
String nonce = notifyResource.getNonce();
String ciphertext = notifyResource.getCiphertext();
@@ -454,43 +450,5 @@
result.put("code", "SUCCESS");
result.put("message", "鎴愬姛");
return result;
- }
-
- /**
- * 鍐嶆绛惧悕
- * @param prepayId 棰勬敮浠樹氦鏄撲細璇濇爣璇�
- * @return 灏忕▼搴忚皟璧锋敮浠樺弬鏁�
- * @throws Exception
- */
- @Operation(summary = "鍐嶆绛惧悕", description = "鍐嶆绛惧悕")
- @ApiResponses(value = {
- @ApiResponse(
- responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- schema = @Schema(implementation = Boolean.class))}
- )
- })
- @GetMapping(path = "/signAgain")
- @Transactional(rollbackFor = Exception.class)
- @SsoAop()
- public BaseResponse<JSONObject> signAgain(@RequestParam("prepayId") String prepayId) throws Exception {
-
- // 鑾峰彇闅忔満涓插拰鏃堕棿鎴筹紝鏀惧湪姝ゅ浠ヤ繚璇�
- String appid = PayInfo.appid;
- String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
- String nonceStr = payHelper.generateRandomString();
- String pkg = "prepay_id=" + prepayId;
- String message = payHelper.buildMessage_signAgain(appid, timestamp, nonceStr, pkg);
- String paySign = payHelper.sign(message.getBytes("utf-8"), privateCertFileName);
-
- JSONObject job_result = new JSONObject();
- job_result.put("timestamp", timestamp);
- job_result.put("nonceStr", nonceStr);
- job_result.put("package", pkg);
- job_result.put("signType", signType);
- job_result.put("paySign", paySign);
-
- return BaseResponseUtils.buildSuccess(job_result) ;
}
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java
index 6a3075d..2dce1c1 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java
@@ -2,10 +2,8 @@
import com.dy.pipIrrGlobal.daoSe.SeOpenIdMapper;
import com.dy.pipIrrGlobal.daoSe.SeVcRechargeMapper;
-import com.dy.pipIrrGlobal.daoSe.SeWebchatLogonStateMapper;
import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
import com.dy.pipIrrGlobal.pojoSe.SeVcRecharge;
-import com.dy.pipIrrGlobal.pojoSe.SeWebchatLogonState;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -21,33 +19,16 @@
@Service
public class PaymentSv {
@Autowired
- private SeWebchatLogonStateMapper seWebchatLogonStateMapper;
-
- @Autowired
private SeVcRechargeMapper seVcRechargeMapper;
@Autowired
private SeOpenIdMapper seOpenIdMapper;
/**
- * 娣诲姞鐧诲綍鎬佺姸鎬佽褰�
- * @param po
- * @return
- */
- Long insert(SeWebchatLogonState po) {
- seWebchatLogonStateMapper.insert(po);
- return po.getId();
- }
-
- /**
* 鏍规嵁鐧诲綍鎬両D鑾峰彇鐧诲綍鎬佸璞�
- * @param id
+ * @param sessionId
* @return
*/
- SeWebchatLogonState selectOne2(Long id) {
- return seWebchatLogonStateMapper.selectByPrimaryKey(id);
- }
-
SeOpenId selectOne(Long sessionId) {
return seOpenIdMapper.selectByPrimaryKey(sessionId);
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/DtoOrder.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/DtoOrder.java
index 66f726d..f4ef320 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/DtoOrder.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/DtoOrder.java
@@ -24,11 +24,11 @@
private Long sessionId;
/**
- * 铏氭嫙鍗$紪鍙凤紝澶栭敭锛岀敤鏉ヨ幏鍙栬櫄鎷熷崱浣欓
+ * 铏氭嫙鍗D锛岀敤鏉ヨ幏鍙栬櫄鎷熷崱浣欓
*/
@Schema(description = "铏氭嫙鍗$紪鍙�", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
- @NotNull(message = "铏氭嫙鍗$紪鍙蜂笉鑳戒负绌�")
- private Long virtualId;
+ @NotNull(message = "铏氭嫙鍗D涓嶈兘涓虹┖")
+ private Long vcId;
/**
* 鍏呭�奸噾棰濋噾棰�
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/NotifyResource.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/NotifyResource.java
new file mode 100644
index 0000000..159d91a
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/NotifyResource.java
@@ -0,0 +1,40 @@
+package com.dy.pipIrrSell.wechatpay.dto;
+
+import lombok.Data;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-13 19:16
+ * @LastEditTime 2024-06-13 19:16
+ * @Description
+ */
+
+@Data
+public class NotifyResource {
+ /**
+ * 鍘熷绫诲瀷
+ * 鍘熷鍥炶皟绫诲瀷涓猴細transaction
+ */
+ private String original_type;
+
+ /**
+ * 鍔犲瘑绠楁硶绫诲瀷
+ * 浠呮敮鎸丄EAD_AES_256_GCM
+ */
+ private String algorithm;
+
+ /**
+ * 鏁版嵁瀵嗘枃
+ */
+ private String ciphertext;
+
+ /**
+ * 闄勫姞鏁版嵁
+ */
+ public String associated_data;
+
+ /**
+ * 闅忔満涓�
+ */
+ private String nonce;
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/OrderNotify.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/OrderNotify.java
index dff01c7..1d44981 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/OrderNotify.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/OrderNotify.java
@@ -48,34 +48,34 @@
private String summary;
- @Data
- public class NotifyResource {
-
- /**
- * 鍔犲瘑绠楁硶绫诲瀷
- * 浠呮敮鎸丄EAD_AES_256_GCM
- */
- private String algorithm;
-
- /**
- * 鏁版嵁瀵嗘枃
- */
- private String ciphertext;
-
- /**
- * 闄勫姞鏁版嵁
- */
- public String associated_data;
-
- /**
- * 鍘熷绫诲瀷
- * 鍘熷鍥炶皟绫诲瀷涓猴細transaction
- */
- private String original_type;
-
- /**
- * 闅忔満涓�
- */
- private String nonce;
- }
+ //@Data
+ //public class NotifyResource {
+ //
+ // /**
+ // * 鍔犲瘑绠楁硶绫诲瀷
+ // * 浠呮敮鎸丄EAD_AES_256_GCM
+ // */
+ // private String algorithm;
+ //
+ // /**
+ // * 鏁版嵁瀵嗘枃
+ // */
+ // private String ciphertext;
+ //
+ // /**
+ // * 闄勫姞鏁版嵁
+ // */
+ // public String associated_data;
+ //
+ // /**
+ // * 鍘熷绫诲瀷
+ // * 鍘熷鍥炶皟绫诲瀷涓猴細transaction
+ // */
+ // private String original_type;
+ //
+ // /**
+ // * 闅忔満涓�
+ // */
+ // private String nonce;
+ //}
}
\ No newline at end of file
--
Gitblit v1.8.0