提交修改
This commit is contained in:
parent
0b68fe0c9e
commit
0a0859cc0e
@ -3,6 +3,7 @@ package com.heyu.api.jsapi;
|
||||
// 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/merchant/4014931831
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.heyu.api.jsapi.dto.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.io.UncheckedIOException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -50,48 +52,60 @@ public class JsapiPrepay {
|
||||
);
|
||||
|
||||
DirectAPIv3JsapiPrepayRequest request = new DirectAPIv3JsapiPrepayRequest();
|
||||
request.setAppid("wx75fa59c097bd3dfd");
|
||||
request.setMchid("1731491745");
|
||||
request.setDescription("Image形象店-深圳腾大-QQ公仔");
|
||||
request.setOutTradeNo("121775250");
|
||||
request.setTimeExpire(WXPayUtility.generateExpireTime()); // 2025-11-05T21:02:16+08:00
|
||||
request.setAttach("自定义数据说明");
|
||||
request.setNotifyUrl("https://api.1024api.com/api-interface/app/weixin/payNotify");
|
||||
request.setGoodsTag("WXG");
|
||||
request.setSupportFapiao(false);
|
||||
|
||||
request.appid = "wx75fa59c097bd3dfd";
|
||||
request.mchid = "1731491745";
|
||||
request.description = "Image形象店-深圳腾大-QQ公仔";
|
||||
request.outTradeNo = "121775250";
|
||||
|
||||
request.timeExpire = WXPayUtility.generateExpireTime(); // 2025-11-05T21:02:16+08:00
|
||||
request.attach = "自定义数据说明";
|
||||
request.notifyUrl = "https://api.1024api.com/api-interface/app/weixin/payNotify";
|
||||
request.goodsTag = "WXG";
|
||||
request.supportFapiao = false;
|
||||
request.amount = new CommonAmountInfo();
|
||||
request.amount.total = 5L;
|
||||
request.amount.currency = "CNY";
|
||||
request.payer = new JsapiReqPayerInfo();
|
||||
CommonAmountInfo commonAmountInfo = new CommonAmountInfo();
|
||||
commonAmountInfo.setTotal(5L);
|
||||
commonAmountInfo.setCurrency("CNY");
|
||||
request.setAmount(commonAmountInfo);
|
||||
|
||||
JsapiReqPayerInfo payer = new JsapiReqPayerInfo();
|
||||
payer.setOpenid("o6t1512tT-JuBeT6rIu6RhF Gf3BQ");
|
||||
request.setPayer(payer);
|
||||
|
||||
CouponInfo couponInfo = new CouponInfo();
|
||||
|
||||
couponInfo.setCostPrice(608800L);
|
||||
couponInfo.setInvoiceId("微信123");
|
||||
request.setDetail(couponInfo);
|
||||
List<GoodsDetail> goodsDetails = new ArrayList<>();
|
||||
|
||||
GoodsDetail goodsDetailItem = new GoodsDetail();
|
||||
goodsDetailItem.setMerchantGoodsId("1246464644");
|
||||
goodsDetailItem.setWechatpayGoodsId("1001");
|
||||
goodsDetailItem.setGoodsName("iPhoneX 256G");
|
||||
goodsDetailItem.setQuantity(1L);
|
||||
goodsDetailItem.setUnitPrice(528800L);
|
||||
goodsDetails.add(goodsDetailItem);
|
||||
couponInfo.setGoodsDetail(goodsDetails);
|
||||
|
||||
CommonSceneInfo sceneInfo = new CommonSceneInfo();
|
||||
sceneInfo.setPayerClientIp("14.23.150.211");
|
||||
sceneInfo.setDeviceId("013467007045764");
|
||||
|
||||
StoreInfo setstoreInfo = new StoreInfo();
|
||||
setstoreInfo.setId("0001");
|
||||
setstoreInfo.setName("腾讯大厦分店");
|
||||
setstoreInfo.setAreaCode("440305");
|
||||
setstoreInfo.setAddress("广东省深圳市南山区科技中一道10000号");
|
||||
|
||||
SettleInfo settleInfo = new SettleInfo();
|
||||
settleInfo.setProfitSharing(false);
|
||||
|
||||
request.setSceneInfo(sceneInfo);
|
||||
sceneInfo.setStoreInfo(setstoreInfo);
|
||||
request.setSettleInfo(settleInfo);
|
||||
|
||||
request.payer.openid = "o6t1512tT-JuBeT6rIu6RhFGf3BQ";
|
||||
|
||||
request.detail = new CouponInfo();
|
||||
request.detail.costPrice = 608800L;
|
||||
request.detail.invoiceId = "微信123";
|
||||
request.detail.goodsDetail = new ArrayList<>();
|
||||
{
|
||||
GoodsDetail goodsDetailItem = new GoodsDetail();
|
||||
goodsDetailItem.merchantGoodsId = "1246464644";
|
||||
goodsDetailItem.wechatpayGoodsId = "1001";
|
||||
goodsDetailItem.goodsName = "iPhoneX 256G";
|
||||
goodsDetailItem.quantity = 1L;
|
||||
goodsDetailItem.unitPrice = 528800L;
|
||||
request.detail.goodsDetail.add(goodsDetailItem);
|
||||
}
|
||||
;
|
||||
request.sceneInfo = new CommonSceneInfo();
|
||||
request.sceneInfo.payerClientIp = "14.23.150.211";
|
||||
request.sceneInfo.deviceId = "013467007045764";
|
||||
request.sceneInfo.storeInfo = new StoreInfo();
|
||||
request.sceneInfo.storeInfo.id = "0001";
|
||||
request.sceneInfo.storeInfo.name = "腾讯大厦分店";
|
||||
request.sceneInfo.storeInfo.areaCode = "440305";
|
||||
request.sceneInfo.storeInfo.address = "广东省深圳市南山区科技中一道10000号";
|
||||
request.settleInfo = new SettleInfo();
|
||||
request.settleInfo.profitSharing = false;
|
||||
try {
|
||||
DirectAPIv3JsapiPrepayResponse response = client.rePay(request);
|
||||
System.out.println(JSON.toJSONString(response));
|
||||
@ -103,6 +117,9 @@ public class JsapiPrepay {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public DirectAPIv3JsapiPrepayResponse rePay(DirectAPIv3JsapiPrepayRequest request) {
|
||||
String uri = PATH;
|
||||
String reqBody = WXPayUtility.toJson(request);
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class CommonAmountInfo {
|
||||
@SerializedName("total")
|
||||
public Long total;
|
||||
private Long total;
|
||||
|
||||
@SerializedName("currency")
|
||||
public String currency;
|
||||
private String currency;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
@ -6,11 +6,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class CommonSceneInfo {
|
||||
@SerializedName("payer_client_ip")
|
||||
public String payerClientIp;
|
||||
private String payerClientIp;
|
||||
|
||||
@SerializedName("device_id")
|
||||
public String deviceId;
|
||||
private String deviceId;
|
||||
|
||||
@SerializedName("store_info")
|
||||
public StoreInfo storeInfo;
|
||||
private StoreInfo storeInfo;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
@ -8,12 +8,12 @@ import java.util.List;
|
||||
@Data
|
||||
public class CouponInfo {
|
||||
@SerializedName("cost_price")
|
||||
public Long costPrice;
|
||||
private Long costPrice;
|
||||
|
||||
@SerializedName("invoice_id")
|
||||
public String invoiceId;
|
||||
private String invoiceId;
|
||||
|
||||
@SerializedName("goods_detail")
|
||||
public List<GoodsDetail> goodsDetail;
|
||||
private List<GoodsDetail> goodsDetail;
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
@ -6,44 +6,45 @@ import lombok.Data;
|
||||
@Data
|
||||
public class DirectAPIv3JsapiPrepayRequest {
|
||||
@SerializedName("appid")
|
||||
public String appid;
|
||||
private String appid;
|
||||
|
||||
|
||||
@SerializedName("mchid")
|
||||
public String mchid;
|
||||
private String mchid;
|
||||
|
||||
@SerializedName("description")
|
||||
public String description;
|
||||
private String description;
|
||||
|
||||
@SerializedName("out_trade_no")
|
||||
public String outTradeNo;
|
||||
private String outTradeNo;
|
||||
|
||||
@SerializedName("time_expire")
|
||||
public String timeExpire;
|
||||
private String timeExpire;
|
||||
|
||||
@SerializedName("attach")
|
||||
public String attach;
|
||||
private String attach;
|
||||
|
||||
@SerializedName("notify_url")
|
||||
public String notifyUrl;
|
||||
private String notifyUrl;
|
||||
|
||||
@SerializedName("goods_tag")
|
||||
public String goodsTag;
|
||||
private String goodsTag;
|
||||
|
||||
@SerializedName("support_fapiao")
|
||||
public Boolean supportFapiao;
|
||||
private Boolean supportFapiao;
|
||||
|
||||
@SerializedName("amount")
|
||||
public CommonAmountInfo amount;
|
||||
private CommonAmountInfo amount;
|
||||
|
||||
@SerializedName("payer")
|
||||
public JsapiReqPayerInfo payer;
|
||||
private JsapiReqPayerInfo payer;
|
||||
|
||||
@SerializedName("detail")
|
||||
public CouponInfo detail;
|
||||
private CouponInfo detail;
|
||||
|
||||
@SerializedName("scene_info")
|
||||
public CommonSceneInfo sceneInfo;
|
||||
private CommonSceneInfo sceneInfo;
|
||||
|
||||
@SerializedName("settle_info")
|
||||
public SettleInfo settleInfo;
|
||||
private SettleInfo settleInfo;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
@ -6,5 +6,5 @@ import lombok.Data;
|
||||
@Data
|
||||
public class DirectAPIv3JsapiPrepayResponse {
|
||||
@SerializedName("prepay_id")
|
||||
public String prepayId;
|
||||
private String prepayId;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
@ -6,17 +6,17 @@ import lombok.Data;
|
||||
@Data
|
||||
public class GoodsDetail {
|
||||
@SerializedName("merchant_goods_id")
|
||||
public String merchantGoodsId;
|
||||
private String merchantGoodsId;
|
||||
|
||||
@SerializedName("wechatpay_goods_id")
|
||||
public String wechatpayGoodsId;
|
||||
private String wechatpayGoodsId;
|
||||
|
||||
@SerializedName("goods_name")
|
||||
public String goodsName;
|
||||
private String goodsName;
|
||||
|
||||
@SerializedName("quantity")
|
||||
public Long quantity;
|
||||
private Long quantity;
|
||||
|
||||
@SerializedName("unit_price")
|
||||
public Long unitPrice;
|
||||
private Long unitPrice;
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class JsapiReqPayerInfo {
|
||||
@SerializedName("openid")
|
||||
public String openid;
|
||||
private String openid;
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SettleInfo {
|
||||
@SerializedName("profit_sharing")
|
||||
public Boolean profitSharing;
|
||||
private Boolean profitSharing;
|
||||
}
|
||||
@ -1,17 +1,20 @@
|
||||
package com.heyu.api.jsapi;
|
||||
package com.heyu.api.jsapi.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class StoreInfo {
|
||||
@SerializedName("id")
|
||||
public String id;
|
||||
private String id;
|
||||
|
||||
@SerializedName("name")
|
||||
public String name;
|
||||
private String name;
|
||||
|
||||
@SerializedName("area_code")
|
||||
public String areaCode;
|
||||
private String areaCode;
|
||||
|
||||
@SerializedName("address")
|
||||
public String address;
|
||||
private String address;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user