package com.api.test;

import com.heyu.api.jsapi.JsapiPrepay;
import com.heyu.api.jsapi.WXPayUtility;
import com.heyu.api.jsapi.dto.pay.DirectAPIv3QueryResponse;
import com.heyu.api.jsapi.dto.pay.QueryByWxTradeNoRequest;

public class JSAPIQueryTest {


    public static void main(String[] args) {
        // TODO: 请准备商户开发必要参数，参考：https://pay.weixin.qq.com/doc/v3/merchant/4013070756
        JsapiPrepay client = new JsapiPrepay(
                TestJSAPI.mchid,                    // 商户号，是由微信支付系统生成并分配给每个商户的唯一标识符，商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756
                TestJSAPI.Certificate_serial_number,         // 商户API证书序列号，如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053
                TestJSAPI.privateKey,     // 商户API证书私钥文件路径，本地文件路径
                TestJSAPI.PUB_KEY_ID,      // 微信支付公钥ID，如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816
                TestJSAPI.wechatPayPublicKey           // 微信支付公钥文件路径，本地文件路径
        );

        QueryByWxTradeNoRequest request = new QueryByWxTradeNoRequest();

        String transactionId = "4200002963202511079867655660";
        request.mchid = TestJSAPI.mchid;
        try {
            DirectAPIv3QueryResponse response = client.queryOrder(transactionId);
            // TODO: 请求成功，继续业务逻辑
            System.out.println(response);
        } catch (WXPayUtility.ApiException e) {
            // TODO: 请求失败，根据状态码执行不同的逻辑
            e.printStackTrace();
        }
    }

}
