189 8069 5689

支付宝netvb接口,支付宝 接口

高分求助,VB.NET 支付宝开发接口

Case 4 '支付宝支付

成都创新互联专业为企业提供番禺网站建设、番禺做网站、番禺网站设计、番禺网站制作等企业网站建设、网页设计与制作、番禺企业网站模板建站服务,十载番禺做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

Dim cmd, subject, body, order_no, prices, rurl, types, number, transport, ordinary_fee, express_fee, readonlytrue, buyer_msg, buyer, buyer_name, buyer_address, buyer_zipcode, buyer_tel, buyer_mobile, partner As String

Dim t1, t2, t3, t4, t5 As String

Dim AlipayObj, itemUrl As String

t1 = ":" '支付接口

t2 = ConfigurationSettings.AppSettings("adminaliPay") '商户支付宝账户(改成你自己的)

t3 = "m7yeav29bcdz14szvi2rbfcixywob59y" '安全校验码

cmd = "0001" '命令码

subject = "订单号:" NoID '商品名称

body = Convert.ToString(ViewState("CourseName")) '商品描述

order_no = NoID '商户订单号

prices = Convert.ToString(ViewState("NowPrice")) '商品单价

rurl = Request.Url.ToString() '商品展示网址

types = "1" '支付类型 1:商品购买,2:服务购买,3:网络拍卖,4:捐赠

number = "1" '购买数量

transport = "3" '发货方式 1:平邮,2:快递,3:虚拟物品

ordinary_fee = "0" '平邮运费

express_fee = "0" '快递运费

readonlytrue = "true" '交易信息是否只读,true或false,默认值为false

buyer_msg = "" '买家给卖家的留言:string(200)

'buyer = Convert.ToString(ViewState("txtIDEmail")) '买家Email

buyer_name = Convert.ToString(ViewState("txtIDName")) ",Email:" Convert.ToString(ViewState("txtIDEmail")) '买家姓名,买家Email

buyer_address = Convert.ToString(ViewState("txtIDaddress")) '买家地址

buyer_zipcode = Convert.ToString(ViewState("txtIDPost")) '买家邮编

buyer_tel = Convert.ToString(ViewState("txtIDtelephone")) '买家电话号码

buyer_mobile = Convert.ToString(ViewState("txtIDTel")) '买家手机号码

partner = "" '合作伙伴ID(保留字段)

itemUrl = creatAlipayItemURL(t1, t2, t3, t4, t5, cmd, subject, body, order_no, prices, rurl, types, number, transport, ordinary_fee, express_fee, readonlytrue, buyer_msg, buyer, buyer_name, buyer_address, buyer_zipcode, buyer_tel, buyer_mobile, partner)

itemUrl = "script language=javascript" vbCrLf "!--" vbCrLf "document.forms[0].submit();" vbCrLf "//--" vbCrLf "/script"

Response.Write(itemUrl)

End Select

接口的VB.NET( 一款行业软件)接口

在VB.NET的类里,实现一个接口的语句是:

implements接口名称

例如,下面定义一个车(总称)的接口,这里的车是各种车的总称:

Public Interface ICar

Property color() As String

Property speed() As Long

Sub PrintInfo()

End Interface

然后在不同类型的“车”类里实现它:

Public Class A_Car

Implements ICar

Dim m_color As String, m_speed As Long

Public Property color() As String Implements ICar.color

Get

Return m_color

End Get

Set(ByVal Value As String)

m_color = Value

End Set

End Property

Protected Overrides Sub Finalize()

MsgBox(I was deconstructed!)

End Sub

Public Sub New()

m_color = Red

m_speed = 210

MsgBox(I was constructed!)

End Sub

Public Property speed() As Long Implements ICar.speed

Get

Return m_speed

End Get

Set(ByVal Value As Long)

m_speed = speed

End Set

End Property

Public Sub PrintInfo() Implements ICar.PrintInfo

MsgBox(Color: m_color vbNewLine Speed: m_speed, MsgBoxStyle.Information)

End Sub

End Class

在 Form 的 Load 事件中编写:

Dim myCar As New A_Car

myCar.PrintInfo()

运行之后就创建了一个 A_Car 类的实例 myCar,然后出现两个对话框,分别说明实例已经创建和汽车的信息。当窗体卸载时,这个类的实例 myCar 将自动销毁,这时将出现一个“I was deconstructed!”的对话框。

声明一个接口时,需要考虑以下几点:

1.接口主体只限于对方法,索引器以及属性的声明;

2.接口成员是隐式公开的,如果对其显式指定访问级别,就会出现编译器错误;

3.接口中不能包含字段,构造函数和常量等;

4.在接口中不能实现任何方法,属性或者索引器;

5.在指定方法时,只需要给出返回类型,名称和参数列表,然后分号结束。

面向对象的接口

在C++中,一个类被允许继承多个类。但是在Java以后的语言不被允许。

这样,如果想继承多个类时便非常困难。所以开发方想出了新办法:接口。

一个接口内,允许包含变量、常量等一个类所包含的基本内容。但是,接口中的函数不允许设定代码,也就意味着不能把程序入口放到接口里。由上可以理解到,接口是专门被继承的。接口存在的意义也是被继承。和C++里的抽象类里的纯虚函数是相同的。不能被实例化。

定义接口的关键字是interface,例如:

publicinterfaceMyInterface{

public void add(int x,int y);

public void volume(int x,int y,int z);

}

继承接口的关键字是implements,相当于继承类的extends。

需要注意的是,当继承一个接口时,接口里的所有函数必须全部被覆盖。例如:

class Demo implements MyInterface{

public void add(int x,int y){

System.out.println( +(x+y));

}

public void volume(int x,int y,int z){

System.out.println( +(x*y*z));

}

public static void main(String args[]){

Demo d=new Demo();

d.add(10,20);

d.volume(10,10,10);

}

}

输出结果:

30

1000

当想继承多个类时,开发程序不允许,报错。这样就要用到接口。因为接口允许多重继承(,),而类不允许。所以就要用到接口。

接入支付宝支付SDK

接入支付宝支付SDK

可以说支付宝支付接入是所有SDK最好接入的,没有之一。

客户端不用签名,也不用管包名,也不用管签名文件,就接口返回订单,把订单交给支付宝SDK调用就行,成功或者失败都在当前界面返回给你。你再去通知接口。

支付流程图

官方文档地址

!支付宝支付官方文档地址

按照文档说明接入SDK和相关配置,在这就不重复了

客户端支付关键代码===》支付接口的调用(调起支付弹框)

记住支付接口的调用必须在独立的非ui线程中执行,即需新开线程里面调用。可以想官方demo一样用new Thread方式。

下面我给出用Observable方式示例代码

在PayUtils中

/**

* desc:支付宝支付

* Created by congge on 2018/8/27 17:20

* @param orderInfo 接口返回的订单

**/

public static void aliPay(final Activity activity, final String orderInfo, final OrderListener orderListener) {

Observable.just(orderInfo)

.map(new Function () {

@Override

public String apply(String orderInfo) throws Exception {

//用户在商户app内部点击付款,是否需要一个loading做为在钱包唤起之前的过渡,这个值设置为true

return new PayTask(activity).pay(orderInfo, true);

}

})

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(new Consumer () {

@Override

public void accept(String payResult) throws Exception {

orderListener.onPayResult(payResult);

}

});

}

支付结果返回处理

返回例子:

resultStatus={9000};memo={};result={{"alipay_trade_app_pay_response":{"code":"10000","msg":"Success","app_id":"2016091300503896","auth_app_id":"2016091300503896","charset":"utf-8","timestamp":"2018-08-28 17:51:11","out_trade_no":"nVElbd74TW6WnEyxQwvX8A","total_amount":"0.01","trade_no":"2018082821001004680500208879","seller_id":"2088102175487650"},"sign":"W0Hg9k4GxL8Oaxymvqk2i65WNDQxYp6HGve32ek6VjSRnymmI3GQTjpQVbZuDzvjcwQ/HIkM97PoBGAVlTmi/wiJcqDgSSDzDY7AFnNN0OcK0ehWGwKQINA4IDGh51A7yY/vYKmR0VW+2OwGhlRPPMMZtQOEqh8a9/aIijzT6ZLwy9Hl4ayG/fVKhdC1VdckF6+C25BFNp3fIxarg5tfEunm7N9iWngKCUsnP+IZz05OHdvynimgYPcBnbBERHG97GVqRT/EdBWTQyIDMc0LemScAYxJixTVgXDkRddQjzWZ7HgLdBfjs0nXY24puHudT76ERxVY+8NkoKle/QI+FA==","sign_type":"RSA2"}}

也可以自己打log看看

处理示例代码:

//支付宝支付

PayUtils.aliPay(this, result.getSignDataStr(), new PayUtils.OrderListener() {

@Override

public void onPayResult(String payResult) {

PayResult pr = new PayResult(payResult);

String rs = pr.getResultStatus();

String r = pr.getResult();

switch (rs) {

case AliPayResultStatus.PAY_SUCCESS:

ToastUtils.show(R.string.pay_success);

//通知接口支付成功

break;

case AliPayResultStatus.PAY_PROCESSING:

case AliPayResultStatus.PAY_UNKNOWN:

ToastUtils.show(R.string.pay_fail);

//支付可能成功,要接口去查询

break;

default:

ToastUtils.show(R.string.pay_fail);

//通知接口支付失败,取消订单

}

}

});

上面方法中:

//通知接口支付成功 //支付可能成功,要接口去查询 //通知接口支付失败,取消订单。根据你产品需求要不要通知你服务器做的操作。正常是要的,用来改变订单状态

PayResult.class

public class PayResult {

private String resultStatus;

private String result;

private String memo;

public PayResult(String rawResult) {

if (TextUtils.isEmpty(rawResult))

return;

String[] resultParams = rawResult.split(";");

for (String resultParam : resultParams) {

if (resultParam.startsWith("resultStatus")) {

resultStatus = gatValue(resultParam, "resultStatus");

}

if (resultParam.startsWith("result")) {

result = gatValue(resultParam, "result");

}

if (resultParam.startsWith("memo")) {

memo = gatValue(resultParam, "memo");

}

}

}

@Override

public String toString() {

return "resultStatus={" + resultStatus + "};memo={" + memo

+ "};result={" + result + "}";

}

private String gatValue(String content, String key) {

String prefix = key + "={";

return content.substring(content.indexOf(prefix) + prefix.length(),

content.lastIndexOf("}"));

}

public String outOrder() {

String order = ""out_trade_no"";

if (result.contains(order)) {

String begin = result.substring(result.indexOf(order));

String ss = begin.split(",")[0];

String newS = ss.replace(""", "")

.replace("}", "")

.replace(":", "")

.replace("out_trade_no", "");

try {

return newS;

} catch (Exception e) {

e.printStackTrace();

}

}

return "";

}

/**

* @return the resultStatus

*/

public String getResultStatus() {

return resultStatus;

}

/**

* @return the memo

*/

public String getMemo() {

return memo;

}

/**

* @return the result

*/

public String getResult() {

return result;

}}

最后给下支付返回码表

AliPayResultStatus.class

public class AliPayResultStatus {

/**

* 订单支付成功,唯一肯定是支付成功的

*/

public static final String PAY_SUCCESS = "9000";

/**

* 正在处理中,支付结果未知(有可能已经支付成功),请查询商户订单列表中订单的支付状态

*/

public static final String PAY_PROCESSING = "8000";

/**

* 订单支付失败

*/

public static final String PAY_FAIL = "4000";

/**

* 重复请求

*/

public static final String PAY_REPEAT = "5000";

/**

* 用户中途取消

*/

public static final String PAY_PROCESS_CANCEL = "6001";

/**

* 网络连接出错

*/

public static final String PAY_NET_ERROR = "6002";

/**

* 支付结果未知(有可能已经支付成功),请查询商户订单列表中订单的支付状态

*/

public static final String PAY_UNKNOWN = "6004";}

还有一个直接弃用沙箱调试模式,否则提示支付失败也有可能不知道错在那,怕金额大,和接口商量,测试服务器就用0.01测试。


当前题目:支付宝netvb接口,支付宝 接口
分享路径:http://cdxtjz.cn/article/hcpicg.html

其他资讯