国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java實(shí)現(xiàn)微信小程序V3支付 (完整demo)

這篇具有很好參考價(jià)值的文章主要介紹了Java實(shí)現(xiàn)微信小程序V3支付 (完整demo)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1. 微信小程序支付-開(kāi)發(fā)者文檔https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml
2. 導(dǎo)入依賴
<!--小程序支付 v3-->
<dependency>
	<groupId>com.github.wechatpay-apiv3</groupId>
	<artifactId>wechatpay-apache-httpclient</artifactId>
	<version>0.4.9</version>
</dependency>
 
3. 微信支付工具類(lèi)
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.PrivateKey;

/**
 * 微信支付工具類(lèi)
 */
@Component
public class WxPayUtils {

    // 商戶號(hào)
    public static final String mchId = "xxxxxxx";
    // AppID(小程序ID)
    public static final String appId = "xxxxxxx";
    // AppSecret(小程序密鑰)
    public static final String appSecret = "xxxxxxx";
    // 授權(quán)
    public final static String grantType = "authorization_code";
    // APIv3密鑰
    public final static String apiV3Key = "xxxxxxx";
    // 證書(shū)序列號(hào) (從p12文件解析)
    public final static String serialnumber = "xxxxxxx";


    // 證書(shū)私鑰
    public static final String privateKey = "xxxxxxx";


    /**
     * 獲取私鑰。
     */
    public static PrivateKey getPrivateKey() throws IOException {
        PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(
                new ByteArrayInputStream(privateKey.getBytes("utf-8")));
        return merchantPrivateKey;
    }
}
4. 微信支付URL工具類(lèi)
public interface ConstantUtils {


    // JSAPI下單
    public final static String JSAPI_URL = "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi";
    // 支付通知
    public final static String NOTIFY_URL = "https://你的線上地址.com";
    // 關(guān)閉訂單
    public final static String CLOSE_PAY_ORDER_URL = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no}/close";
    // 查詢訂單 (根據(jù)商戶訂單號(hào)查詢)
    public final static String QUERY_PAY_RESULT_URL = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/";
}
5. 微信支付API v3 HttpClient (自動(dòng)處理簽名和驗(yàn)簽)
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
import com.wechat.pay.contrib.apache.httpclient.exception.HttpCodeException;
import com.wechat.pay.contrib.apache.httpclient.exception.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;


@Slf4j
@Component
@Order(3)
public class WechatPayaHttpclientUtils implements ApplicationRunner {

     // 商戶API私鑰
     public static PrivateKey merchantPrivateKey;
     // verifier
     public static Verifier verifier;
     // httpClient
     public static CloseableHttpClient httpClient;


    @Override
    public void run(ApplicationArguments args) {
        log.info("----------->構(gòu)造微信支付API v3 HttpClient");
        createHttpClient();
    }


    /***
     * 微信支付API v3 HttpClient
     *
     * 自動(dòng)處理簽名和驗(yàn)簽
     *
     * @return
     */
    public void createHttpClient() {
        try {

            merchantPrivateKey = WxPayUtils.getPrivateKey();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 獲取證書(shū)管理器實(shí)例
        CertificatesManager certificatesManager = CertificatesManager.getInstance();
        try {
            // 向證書(shū)管理器增加需要自動(dòng)更新平臺(tái)證書(shū)的商戶信息
            certificatesManager.putMerchant(WxPayUtils.mchId, new WechatPay2Credentials(WxPayUtils.mchId,
                    new PrivateKeySigner(WxPayUtils.serialnumber, merchantPrivateKey)), WxPayUtils.apiV3Key.getBytes(StandardCharsets.UTF_8));
            // ... 若有多個(gè)商戶號(hào),可繼續(xù)調(diào)用putMerchant添加商戶信息
        } catch (IOException e) {
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        } catch (HttpCodeException e) {
            e.printStackTrace();
        }
        try {
            // 從證書(shū)管理器中獲取verifier
            verifier = certificatesManager.getVerifier(WxPayUtils.mchId);
        } catch (NotFoundException e) {
            e.printStackTrace();
        }
        WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
                .withMerchant(WxPayUtils.mchId, WxPayUtils.serialnumber, merchantPrivateKey)
                .withValidator(new WechatPay2Validator(verifier));
        // ... 接下來(lái),你仍然可以通過(guò)builder設(shè)置各種參數(shù),來(lái)配置你的HttpClient

        // 通過(guò)WechatPayHttpClientBuilder構(gòu)造的HttpClient,會(huì)自動(dòng)的處理簽名和驗(yàn)簽
        httpClient = builder.build();
    }
}
6. controller
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.ruoyils.sy.order.domain.LsOrder;
import com.ruoyi.ruoyils.wx.pay.service.IWxPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Api(value = "微信-支付", tags = {"微信-支付"})
@RestController
@RequestMapping("/ls/wx/pay")
public class WxPayController extends BaseController {

    @Autowired
    private IWxPayService wxPayService;


    /**
     * jsapi下單
     *
     * @param lsOrder   訂單
     * @return
     */
    @ApiOperation("統(tǒng)一下單")
    @PostMapping(value = "/payment")
    public AjaxResult payment(@RequestBody LsOrder lsOrder) {
        return wxPayService.addOrder(lsOrder);
    }


    /**
     * 支付通知
     *
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/notifyUrl")
    public AjaxResult notifyUrl(HttpServletRequest request, HttpServletResponse response) {
        return AjaxResult.success(wxPayService.notifyUrl(request, response));
    }

}
7. service

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.ContentType;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.sign.Base64;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.ruoyils.exception.MyException;
import com.ruoyi.ruoyils.sy.append.domain.LsAppend;
import com.ruoyi.ruoyils.sy.append.mapper.LsAppendMapper;
import com.ruoyi.ruoyils.sy.order.domain.LsOrder;
import com.ruoyi.ruoyils.sy.order.mapper.LsOrderMapper;
import com.ruoyi.ruoyils.sy.order.service.impl.LsOrderServiceImpl;
import com.ruoyi.ruoyils.sy.product.domain.LsProduct;
import com.ruoyi.ruoyils.sy.product.mapper.LsProductMapper;
import com.ruoyi.ruoyils.utils.*;
import com.ruoyi.ruoyils.wx.pay.service.IWxPayService;
import com.ruoyi.ruoyils.wx.user.domain.LsUser;
import com.ruoyi.ruoyils.wx.user.mapper.LsUserMapper;
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.wechat.pay.contrib.apache.httpclient.notification.Notification;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationHandler;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.security.Signature;
import java.util.*;

@Order(5)
@Slf4j
@Service
public class WxPayServiceImpl implements IWxPayService {

    @Autowired
    private LsOrderMapper orderMapper;
    @Autowired
    private LsUserMapper lsUserMapper;
    @Autowired
    private LsProductMapper lsProductMapper;
    @Autowired
    private LsAppendMapper lsAppendMapper;


    /**
     * 立即下單
     *
     * @param lsOrder 訂單
     * @return 結(jié)果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AjaxResult addOrder(LsOrder lsOrder) {

            // TODO 訂單業(yè)務(wù)操作

            // 生成訂單
            int i = orderMapper.insertLsOrder(lsOrder);
            if (i > 0) {
                // 調(diào)起支付
                AjaxResult payment = this.payment(lsOrder);
                return payment;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return AjaxResult.error("下單失敗 !");
    }


    /**
     * 調(diào)起支付
     *
     * @param lsOrder
     * @return
     */

    @Override
    public AjaxResult payment(LsOrder lsOrder) {
        try {
            JSONObject order = new JSONObject();
            // 應(yīng)用ID
            order.put("appid",WxPayUtils.appId);
            // 商戶號(hào)
            order.put("mchid",WxPayUtils.mchId);
            // 商品描述
            order.put("description",lsOrder.getProductName());
            // 訂單號(hào)
            order.put("out_trade_no",lsOrder.getOrderNo());
            // 通知地址
            order.put("notify_url",ConstantUtils.NOTIFY_URL+"/ls/wx/pay/notifyUrl");
            /**訂單金額*/
            JSONObject amount = new JSONObject();
            // 總金額 (默認(rèn)單位分)
//            amount.put("total",lsOrder.getTotalPrice().intValue()*100);
            amount.put("total",1);
            // 貨幣類(lèi)型
            amount.put("currency","CNY");
            order.put("amount",amount);

            /**支付者*/
            JSONObject payer = new JSONObject();
            LsUser user = SpringUtils.getBean(LsUserMapper.class).selectLsUserById(lsOrder.getUserId());
            // 用戶標(biāo)識(shí)
            payer.put("openid",user.getOpenid());
            order.put("payer",payer);

            // 微信httpClient
            CloseableHttpClient httpClient = WechatPayaHttpclientUtils.httpClient;
            if (httpClient == null) {
                log.info("預(yù)下單請(qǐng)求失敗");
                return AjaxResult.error("預(yù)下單失敗,請(qǐng)重試,無(wú)法連接微信支付服務(wù)器!");
            }

            HttpPost httpPost = new HttpPost(ConstantUtils.JSAPI_URL);
            httpPost.addHeader("Accept", "application/json");
            httpPost.addHeader("Content-type","application/json; charset=utf-8");
            httpPost.setEntity(new StringEntity(order.toJSONString(), "UTF-8"));
            // 后面跟使用Apache HttpClient一樣
            CloseableHttpResponse response = httpClient.execute(httpPost);
            String bodyAsString = EntityUtils.toString(response.getEntity());

            JSONObject bodyAsJSON = JSONObject.parseObject(bodyAsString);
            String message = bodyAsJSON.getString("message");
            // 返回code, 說(shuō)明請(qǐng)求失敗
            if (bodyAsJSON.containsKey("code")) {
                log.info("預(yù)下單請(qǐng)求失敗{}", message);
                return AjaxResult.error("預(yù)下單失敗,請(qǐng)重試!" + message);
            }

            // 返回預(yù)支付id
            final String prepay_id = bodyAsJSON.getString("prepay_id");
            if (StringUtils.isEmpty(prepay_id)) {
                log.info("預(yù)下單請(qǐng)求失敗{}", message);
                return AjaxResult.error("預(yù)下單失敗,請(qǐng)重試!" + message);
            }

            LsOrder preOrder = new LsOrder();
            preOrder.setId(lsOrder.getId());
            preOrder.setPrepayId(prepay_id);
            orderMapper.updateLsOrder(preOrder);

            // JSAPI調(diào)起支付API: 此API無(wú)后臺(tái)接口交互,需要將列表中的數(shù)據(jù)簽名
            // 隨機(jī)字符串
            final String nonceStr = RandomNumberUtils.getRandomString(32,false);
            // 時(shí)間戳
            String timeStamp = String.valueOf(System.currentTimeMillis());
            /*簽名*/
            StringBuilder sb = new StringBuilder();
            sb.append(WxPayUtils.appId + "\n"); //小程序appId
            sb.append(timeStamp + "\n"); //時(shí)間戳
            sb.append(nonceStr + "\n"); //隨機(jī)字符串
            sb.append("prepay_id=" + prepay_id + "\n"); //訂單詳情擴(kuò)展字符串
            Signature signature = Signature.getInstance("SHA256withRSA");
            signature.initSign(WechatPayaHttpclientUtils.merchantPrivateKey);
            signature.update(sb.toString().getBytes("UTF-8"));
            byte[] signBytes = signature.sign();
            String paySign = Base64.encode(signBytes);

            JSONObject params = new JSONObject();
            params.put("appId", WxPayUtils.appId);
            params.put("timeStamp", timeStamp);
            params.put("nonceStr", nonceStr);
            params.put("package", "prepay_id="+prepay_id);
            params.put("signType", "RSA");
            params.put("paySign", paySign);

            return AjaxResult.success(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error("預(yù)下單失敗,請(qǐng)重試!");
    }

    /**
     * 支付通知
     *
     * @param servletRequest
     * @param response
     * @return
     */
    @Override
    public AjaxResult notifyUrl(HttpServletRequest servletRequest, HttpServletResponse response) {
        log.info("----------->微信支付回調(diào)開(kāi)始<-----------");
        Map<String, String> map = new HashMap<>(12);
        String timeStamp = servletRequest.getHeader("Wechatpay-Timestamp");
        String nonce = servletRequest.getHeader("Wechatpay-Nonce");
        String signature = servletRequest.getHeader("Wechatpay-Signature");
        String certSn = servletRequest.getHeader("Wechatpay-Serial");
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(servletRequest.getInputStream()))) {
            StringBuilder stringBuilder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
            }
            String obj = stringBuilder.toString();
            log.info("支付回調(diào)請(qǐng)求參數(shù):{},{},{},{},{}", obj, timeStamp, nonce, signature, certSn);

            // 從證書(shū)管理器中獲取verifier
            Verifier verifier = WechatPayaHttpclientUtils.verifier;

            String sn = verifier.getValidCertificate().getSerialNumber().toString(16).toUpperCase(Locale.ROOT);
            NotificationRequest request = new NotificationRequest.Builder().withSerialNumber(sn)
                    .withNonce(nonce)
                    .withTimestamp(timeStamp)
                    .withSignature(signature)
                    .withBody(obj)
                    .build();
            NotificationHandler handler = new NotificationHandler(verifier, WxPayUtils.apiV3Key.getBytes(StandardCharsets.UTF_8));
            // 驗(yàn)簽和解析請(qǐng)求體
            Notification notification = handler.parse(request);
            JSONObject bodyAsJSON = JSON.parseObject(notification.getDecryptData());
            log.info("支付回調(diào)響應(yīng)參數(shù): {}", bodyAsJSON.toJSONString());
            //做一些操作
            if (bodyAsJSON != null) {
                //如果支付成功
                String tradeState = bodyAsJSON.getString("trade_state");
                if("SUCCESS".equals(tradeState)){
                    //拿到商戶訂單號(hào)
                    String outTradeNo = bodyAsJSON.getString("out_trade_no");
                    JSONObject amountJson = bodyAsJSON.getJSONObject("amount");
                    Integer payerTotal = amountJson.getInteger("payer_total");
                    LsOrder order = orderMapper.selectLsOrderByOrderNo(outTradeNo);
                    if(order != null){
                        if(order.getStatus() == 1){
                            //如果支付狀態(tài)為1 說(shuō)明訂單已經(jīng)支付成功了,直接響應(yīng)微信服務(wù)器返回成功
                            response.setStatus(200);
                            map.put("code", "SUCCESS");
                            map.put("message", "SUCCESS");
                            response.setHeader("Content-type", ContentType.JSON.toString());
                            response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
                            response.flushBuffer();
                        }
                        //驗(yàn)證用戶支付的金額和訂單金額是否一致
                        if(payerTotal.equals(order.getTotalPrice())){
                            //修改訂單狀態(tài)
                            String successTime = bodyAsJSON.getString("success_time");
                            order.setStatus(1);
                            order.setPaymentTime(DateUtils.rfcToDate(successTime));
                            orderMapper.updateLsOrder(order);
                            //響應(yīng)微信服務(wù)器
                            response.setStatus(200);
                            map.put("code", "SUCCESS");
                            map.put("message", "SUCCESS");
                            response.setHeader("Content-type", ContentType.JSON.toString());
                            response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
                            response.flushBuffer();
                        }
                    }
                }
            }
            response.setStatus(500);
            map.put("code", "FAIL");
            map.put("message", "簽名錯(cuò)誤");
            response.setHeader("Content-type", ContentType.JSON.toString());
            response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
            response.flushBuffer();
        } catch (Exception e) {
            log.error("微信支付回調(diào)失敗", e);
        }
        return AjaxResult.error("微信支付回調(diào)失敗");
    }

    /**
     * 關(guān)閉訂單
     *
     * @param orderNo
     * @return
     */
    public boolean closePayOrder(String orderNo) {
        JSONObject obj = new JSONObject();
        // 直連商戶號(hào)
        obj.put("mchid", WxPayUtils.mchId);
        // 請(qǐng)求地址
        String closeOrderUrl = ConstantUtils.CLOSE_PAY_ORDER_URL.replace("{out_trade_no}", orderNo);

        HttpPost httpPost = new HttpPost(closeOrderUrl);
        httpPost.addHeader("Accept", "application/json");
        httpPost.addHeader("Content-type", "application/json; charset=utf-8");
        httpPost.setEntity(new StringEntity(obj.toJSONString(), "UTF-8"));

        // 微信httpClient
        CloseableHttpClient httpClient = WechatPayaHttpclientUtils.httpClient;
        try {
            if(httpClient == null){
                log.info("關(guān)閉訂單失敗,請(qǐng)重試,無(wú)法連接微信支付服務(wù)器!");
            }
            //執(zhí)行請(qǐng)求
            CloseableHttpResponse response = httpClient.execute(httpPost);
            //狀態(tài)碼
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 204) {
                //關(guān)閉訂單成功!
                log.info("微信關(guān)閉訂單成功: {}", orderNo);
            }else if(statusCode == 202){
                //用戶支付中,需要輸入密碼
                log.info("關(guān)閉微信訂單--用戶支付中,需要輸入密碼,暫時(shí)不做處理!");
            }else{
                log.info("關(guān)閉微信訂單--關(guān)閉支付訂單失敗,出現(xiàn)未知原因: {}", EntityUtils.toString(response.getEntity()));
            }
        } catch (IOException e) {
            log.info("關(guān)閉微信訂單--關(guān)閉訂單失敗: {}", e.getMessage());
        }
        return false;
    }

    /**
     * 訂單查詢 (定時(shí)查詢訂單, 修改訂單狀態(tài))
     *
     * @return
     */
    @Scheduled(cron="0/10 * * * * ?")
    public void queryOrder() {

        LsOrder od = new LsOrder();
        od.setStatus(3); //未支付
        List<LsOrder> list = SpringUtils.getBean(LsOrderMapper.class).selectLsOrderList(od);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        try {
            for (LsOrder lsOrder : list) {
                // 根據(jù)商戶訂單號(hào)查詢
                URIBuilder uriBuilder = new URIBuilder(ConstantUtils.QUERY_PAY_RESULT_URL+lsOrder.getOrderNo());
                uriBuilder.setParameter("mchid", WxPayUtils.mchId);

                HttpGet httpGet = new HttpGet(uriBuilder.build());
                httpGet.addHeader("Accept", "application/json");

                CloseableHttpClient httpClient = WechatPayaHttpclientUtils.httpClient;
                if (httpClient == null) {
                    return;
                }
                CloseableHttpResponse response = httpClient.execute(httpGet);
                String bodyAsString = EntityUtils.toString(response.getEntity());
                JSONObject data = JSON.parseObject(bodyAsString);
                log.info("微信訂單查詢:{}", data);

                // 商戶訂單號(hào)
                String outTradeNo = data.getString("out_trade_no");
                // 交易狀態(tài) SUCCESS:支付成功, REFUND:轉(zhuǎn)入退款, NOTPAY:未支付, CLOSED:已關(guān)閉
                String tradeState = data.getString("trade_state");
                // 支付完成時(shí)間
                String successTime = data.getString("success_time");
                Date date = DateUtils.rfcToDate(successTime);


                if (StringUtils.isNotEmpty(outTradeNo) && StringUtils.isNotEmpty(tradeState)) {
                    switch (tradeState) {
                        case "SUCCESS":
                            log.info("支付成功商戶訂單號(hào): {}",outTradeNo);
                            lsOrder.setStatus(1);
                            lsOrder.setPaymentTime(date);
                            orderMapper.updateLsOrder(lsOrder);
                            break;
                        case "REFUND":
                            break;
                        case "NOTPAY":
                            // 查詢訂單未支付 截止時(shí)間是否超時(shí)
                            if (DateUtils.compareCurrentDateToEndDate(lsOrder.getNoPaymentCutoffTime())) {
                                lsOrder.setStatus(0);
                                if (orderMapper.updateLsOrder(lsOrder)>0) {
                                    // 微信關(guān)閉訂單
                                    closePayOrder(lsOrder.getOrderNo());
                                }
                            }
                            break;
                        case "CLOSED":
                            log.info("已關(guān)閉商戶訂單號(hào): {}",outTradeNo);
                            lsOrder.setStatus(0);
                            orderMapper.updateLsOrder(lsOrder);
                            break;
                    }
                } else {
                    log.info(data.getString("message"));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
8. 返回給前端調(diào)起支付的必要參數(shù)
{
    "msg": "操作成功",
    "code": 200,
    "data": {
        "timeStamp": "1692334223808",
        "package": "prepay_id=wx18125024326178678d4e07673e277c0000",
        "paySign": "ocI64smXYkantoHEIkv7fibP0Y83pUmoVN1pQAjrJnFRI75sXCmQt09emPMhZJ+ujuemaGinJdJjmvGZv1JFoWvGSaMv8imDxOQV2EBr9QI+gybtUyC57+H2PhjXIR4gF0M8n7yv6Q9TA+7EIfpXOTaMJjDzM4AkFhAwz/quUAAEJVPLuaMsyF1xqi1qSY9AnE309YhqVG6ETDbZeP9/fuGCs9gD1HdD14HF4BndU696wR4TQdoiTzIyOokrE21oZLdK6Tp6sBPj2mGiIFX8viEHxq8GWOEMOIQXlr4NId4hrYA1Nn6xLk2Ka75t2t8L5V//3rWmbGSOaE5nrkeJcg==",
        "appId": "xxxxxxxxxxxxxx",
        "signType": "RSA",
        "nonceStr": "KFW6FBHHDMALH1A39FM07HKXM7I0T1GR"
    }
}

java 微信小程序支付,微信小程序 V3,微信小程序,小程序,java文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-723574.html

男性深夜解壓 【榨汁女神】

https://shop321260254.taobao.com/?spm=2013.1.1000126.d21.7e1d3db3oibAUR

到了這里,關(guān)于Java實(shí)現(xiàn)微信小程序V3支付 (完整demo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 微信小程序支付V3版本接口實(shí)現(xiàn)

    微信小程序支付V3版本接口實(shí)現(xiàn)

    特別說(shuō)明:遇到 java.security.InvalidKeyException: Illegal key size ******* getValidator的錯(cuò)誤 參考添加鏈接描述 JDK7的下載地址 JDK8的下載地址: 下載后解壓,可以看到local_policy.jar和US_export_policy.jar以及readme.txt 如果安裝了JRE,將兩個(gè)jar文件放到%JRE_HOME%libsecurity目錄下覆蓋原來(lái)的文件 如果安

    2024年02月09日
    瀏覽(26)
  • springboot實(shí)現(xiàn)微信小程序V3微信支付功能

    appId:小程序appid appSecret:小程序的secret mchId:商戶號(hào) keyPath:商戶私鑰路徑(apiclient_key.pem) certPath:證書(shū)路徑(apiclient_cert.pem) platFormPath:平臺(tái)證書(shū)(cert.pem) 注 : 需要通過(guò)寫(xiě)程序生成平臺(tái)證書(shū)(見(jiàn)v3Get()方法) apiKey3:apiv3密鑰 serialnumber:商戶證書(shū)序列號(hào) notifyUrl:回調(diào)地

    2024年02月12日
    瀏覽(99)
  • springboot整合IJPay實(shí)現(xiàn)微信支付-V3---微信小程序

    springboot整合IJPay實(shí)現(xiàn)微信支付-V3---微信小程序

    微信支付適用于許多場(chǎng)合,如小程序、網(wǎng)頁(yè)支付、但微信支付相對(duì)于其他支付方式略顯麻煩,我們使用IJpay框架進(jìn)行整合 JPay 讓支付觸手可及, 封裝了微信支付、支付寶支付、銀聯(lián)支付常用的支付方式以及各種常用的接口。不依賴任何第三方 mvc 框架,僅僅作為工具使用簡(jiǎn)單

    2024年02月02日
    瀏覽(57)
  • Java實(shí)現(xiàn)微信支付v3的支付回調(diào)

    Java實(shí)現(xiàn)微信支付v3的支付回調(diào)

    以前都是自己手搓api的, 現(xiàn)在有輪子了, 嘗試記錄一下如何使用 我的做法是首先打開(kāi)v3的代碼倉(cāng)庫(kù), 直接進(jìn)去看看他們的文檔, 可以看到這么一坨東西 開(kāi)發(fā)前準(zhǔn)備 2. 先引入maven 初始化商戶配置 先從請(qǐng)求頭中獲取構(gòu)建RequestParam需要的參數(shù) 初始化解析器 進(jìn)行驗(yàn)簽, 解密并轉(zhuǎn)換成

    2024年02月12日
    瀏覽(27)
  • 小程序微信支付V3版本Java集成

    相較于之前的微信支付API,主要區(qū)別是: 遵循統(tǒng)一的REST的設(shè)計(jì)風(fēng)格 使用JSON作為數(shù)據(jù)交互的格式,不再使用XML 使用基于非對(duì)稱密鑰的SHA256-RSA的數(shù)字簽名算法,不再使用MD5或HMAC-SHA256 不再要求攜帶HTTPS客戶端證書(shū)(僅需攜帶證書(shū)序列號(hào)) 使用AES-256-GCM,對(duì)回調(diào)中的關(guān)鍵信息進(jìn)

    2024年02月11日
    瀏覽(20)
  • 【微信小程序】Java實(shí)現(xiàn)微信支付(小程序支付JSAPI-V3)java-sdk工具包

    【微信小程序】Java實(shí)現(xiàn)微信支付(小程序支付JSAPI-V3)java-sdk工具包

    ? ? ? 對(duì)于一個(gè)沒(méi)有寫(xiě)過(guò)支付的小白,打開(kāi)微信支付官方文檔時(shí)徹底懵逼 ,因?yàn)?微信支付文檔太過(guò)詳細(xì), 導(dǎo)致我無(wú)從下手,所以寫(xiě)此文章,幫助第一次寫(xiě)支付的小伙伴梳理一下。 一、流程分為三個(gè)接口:(這是前言,先看一遍,保持印象,方便理解代碼) 1、第一個(gè)接口:

    2024年02月03日
    瀏覽(30)
  • 微信小程序基于java實(shí)現(xiàn)v2支付,提現(xiàn),退款

    微信小程序基于java實(shí)現(xiàn)v2支付,提現(xiàn),退款

    v2微信官方文檔 封裝支付請(qǐng)求實(shí)體 controller接口暴露層 payFoodOrder 支付接口實(shí)現(xiàn)類(lèi) 獲取請(qǐng)求ip wxform.setNotifyUrl(WechatUtil.getPayNotifyUrl() + WXPAY_NOTIFY_URL_FOOD_ORDER); 這個(gè)回調(diào)地址是你自己代碼里面定義的回調(diào)接口,例如你定義的controller回調(diào)接口url是 feedback/wx/notifurl , 即是 wxform.setNoti

    2024年02月09日
    瀏覽(24)
  • 微信小程序完整實(shí)現(xiàn)微信支付功能(SpringBoot和小程序)

    微信小程序完整實(shí)現(xiàn)微信支付功能(SpringBoot和小程序)

    1.前言 不久前給公司實(shí)現(xiàn)支付功能,折騰了一陣子,終于實(shí)現(xiàn)了,微信支付對(duì)于小白來(lái)說(shuō)真的很困難,特別是沒(méi)有接觸過(guò)企業(yè)級(jí)別開(kāi)發(fā)的大學(xué)生更不用說(shuō),因此嘗試寫(xiě)一篇我如何從小白實(shí)現(xiàn)微信小程序支付功能的吧,使用的后端是 SpringBoot 。 2.準(zhǔn)備工作 首先,要實(shí)現(xiàn)支付功能

    2024年02月04日
    瀏覽(34)
  • 【微信小程序】Java實(shí)現(xiàn)微信支付(小程序支付JSAPI-V3)java-sdk工具包(包含支付出現(xiàn)的多次回調(diào)的問(wèn)題解析,接口冪等性)

    【微信小程序】Java實(shí)現(xiàn)微信支付(小程序支付JSAPI-V3)java-sdk工具包(包含支付出現(xiàn)的多次回調(diào)的問(wèn)題解析,接口冪等性)

    ? ? ? 對(duì)于一個(gè)沒(méi)有寫(xiě)過(guò)支付的小白,打開(kāi)微信支付官方文檔時(shí)徹底懵逼 ,因?yàn)?微信支付文檔太過(guò)詳細(xì), 導(dǎo)致我無(wú)從下手,所以寫(xiě)此文章,幫助第一次寫(xiě)支付的小伙伴梳理一下。 一、流程分為三個(gè)接口:(這是前言,先看一遍,保持印象,方便理解代碼) 1、第一個(gè)接口:

    2024年01月16日
    瀏覽(30)
  • uniapp+java/springboot實(shí)現(xiàn)微信小程序APIV3支付功能

    uniapp+java/springboot實(shí)現(xiàn)微信小程序APIV3支付功能

    微信小程序的支付跟H5的支付和APP支付流程不一樣,本次只描述下小程序支付流程。 1.微信小程序賬號(hào) 文檔:小程序申請(qǐng) 小程序支付需要先認(rèn)證,如果你有已認(rèn)證的公眾號(hào),也可以通過(guò)公眾號(hào)免費(fèi)注冊(cè)認(rèn)證小程序。 一般300元,我是認(rèn)證的政府的免費(fèi)。 然后登錄小程序,設(shè)置

    2023年04月19日
    瀏覽(31)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包