微信支付通用支付接口

微信支付通用支付接口

一 原理

因微信扫码支付的特殊性,因此其无法提供地址重定向功能,需要我们自己编写 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;
	}
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值