wuzeyu
2024-06-17 5c1a8a48f73591002189a99db030440208f056b5
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java
@@ -18,6 +18,7 @@
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;
@@ -73,6 +74,7 @@
    private final String privateCertFileName = PayInfo.privateCertFileName;
    private final String appid = PayInfo.appid;
    private final String secret = PayInfo.secret;
    private final String mchid = PayInfo.mchid;
    private final String schema = PayInfo.schema;
    private final String signType = PayInfo.signType;
@@ -83,6 +85,68 @@
    // 平台证书公钥
    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 = "操作结果:true:成功,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());
        }
        String phoneNumber = code2Session.getPhoneNumber();
        String jsCode = code2Session.getJs_code();
        Map<String, Object> queryParams = new HashMap<>();
        queryParams.put("appid", appid);
        queryParams.put("secret", secret);
        queryParams.put("js_code", jsCode);
        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");
        Long clientId = clientSv.getClientIdByPhone(phoneNumber);
        String SessionId = "";
        if(clientId != null) {
            // 添加微信用户账户记录
            SeOpenId seOpenId = new SeOpenId();
            seOpenId.setClientId(clientId);
            seOpenId.setOpenId(openid);
            seOpenId.setSessionKey(sessionKey);
            seOpenId.setCreateTime(new Date());
            Long rec = clientSv.addOpenId(seOpenId);
            if(rec != null) {
                SessionId = String.valueOf(rec);
            }
            return BaseResponseUtils.buildSuccess(SessionId);
        } else {
            return BaseResponseUtils.buildError(SellResultCode.PHONE_NUMBER_IS_ERROR.getMessage());
        }
    }
    /**
     * 下载微信支付平台证书 测试完废除
@@ -221,6 +285,7 @@
        if(job_result == null) {
            return BaseResponseUtils.buildFail(SellResultCode.RECHARGE_ADD_FAIL.getMessage());
        }
        return BaseResponseUtils.buildSuccess(job_result) ;
    }