一 原理
因微信扫码支付的特殊性,因此其无法提供地址重定向功能,需要我们自己编写 websocket 来实现功能,所以特地提供一个已经继承了 websocket 的支付页面和服务端,大家只要将订单号,商品名称,商品价格,和回调地址数据通过浏览器提交过去即可(页面 form 表单提交或者程序内部拼接后重定向),支付接口在支付完成后会自动指定重定向功能,跳转回你指定的页面
二 请求参数
参数名称 | 参数介绍 | 参数格式 | 示例 | 是否必填 | 备注 |
---|---|---|---|---|---|
price | 商品价格 | 字符串 | 1 | 是 | 单位:分 |
body | 商品标题介绍 | 字符串 | 颈椎康复指南 | 是 | |
orderId | 订单号 | 字符串 | dsd3sf3wsef | 是 | 你网站的订单号 |
url | 回调地址 | 字符串 | http://localhost:8080/abc | 是 | 必须 http 开头 |
三 支付结果
当扫码支付完成后,程序会请求前面传递的回调地址接口,然后将结果传递过去
你在内部只需要判断支付结果,给对应的订单更改状态即可
参数名 | 值 |
---|---|
result | 下面 json 数据,注意参数名是 result, 值里面也是 result 开头 |
{
"result":
{
"appid":"wx632c8f211f8122c6",
"bank_type":"CFT",
"cash_fee":"1",
"fee_type":"CNY",
"is_subscribe":"Y",
"mch_id":"1497984412",
"nonce_str":"1631171182",
"openid":"oUuptwrJudIfdihz1Z_T1AciMahs",
"out_trade_no":"1221ea762d54496e83a33c9dab72f320",//订单编号
"result_code":"SUCCESS",//支付结果
"return_code":"SUCCESS",
"sign":"5C7314AA4EB21772B42DBBCD65E56ACF",
"time_end":"20180207163125",
"total_fee":"1",//总支付价格
"trade_type":"NATIVE",
"transaction_id":"4200000065201802078895888133"},
"type":0//类型 0为页面重定向,1为点对点服务器通信,因为是 localhost 地址,无法使用1
}
对应实体类
微信实体类:
public class WeiXin {
private Result result;
private String type;
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public WeiXin(Result result, String type) {
super();
this.result = result;
this.type = type;
}
public WeiXin() {
super();
}
}
结果实体类
public class Result {
private String appid;
private String bank_type;
private String cash_fee;
private String is_subscribe;
private String mch_id;
private String nonce_str;
private String openid;
private String out_trade_no;
private String result_code;//支付结果
private String return_code;
private String sign;
private String time_end;
private String total_fee;//总支付价格
private String trade_type;
private String transaction_id;
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getBank_type() {
return bank_type;
}
public void setBank_type(String bank_type) {
this.bank_type = bank_type;
}
public String getCash_fee() {
return cash_fee;
}
public void setCash_fee(String cash_fee) {
this.cash_fee = cash_fee;
}
public String getIs_subscribe() {
return is_subscribe;
}
public void setIs_subscribe(String is_subscribe) {
this.is_subscribe = is_subscribe;
}
public String getMch_id() {
return mch_id;
}
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getNonce_str() {
return nonce_str;
}
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getOut_trade_no() {
return out_trade_no;
}
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getResult_code() {
return result_code;
}
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getReturn_code() {
return return_code;
}
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getTime_end() {
return time_end;
}
public void setTime_end(String time_end) {
this.time_end = time_end;
}
public String getTotal_fee() {
return total_fee;
}
public void setTotal_fee(String total_fee) {
this.total_fee = total_fee;
}
public String getTrade_type() {
return trade_type;
}
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getTransaction_id() {
return transaction_id;
}
public void setTransaction_id(String transaction_id) {
this.transaction_id = transaction_id;
}
public Result(String appid, String bank_type, String cash_fee, String is_subscribe, String mch_id, String nonce_str,
String openid, String out_trade_no, String result_code, String return_code, String sign, String time_end,
String total_fee, String trade_type, String transaction_id) {
super();
this.appid = appid;
this.bank_type = bank_type;
this.cash_fee = cash_fee;
this.is_subscribe = is_subscribe;
this.mch_id = mch_id;
this.nonce_str = nonce_str;
this.openid = openid;
this.out_trade_no = out_trade_no;
this.result_code = result_code;
this.return_code = return_code;
this.sign = sign;
this.time_end = time_end;
this.total_fee = total_fee;
this.trade_type = trade_type;
this.transaction_id = transaction_id;
}
}