预览
代码
手机端效果
demoAliPay.cs
demoAliPay.Designer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Aop.Api;
using Aop.Api.Request;
using Aop.Api.Domain;
using Aop.Api.Response;
namespace Smobiler.Tutorials.Plugins
{
partial class demoAliPay : Smobiler.Core.Controls.MobileForm
{
public demoAliPay()
: base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
}
private void title1_ImagePress(object sender, EventArgs e)
{
this.Close();
}
private string tradeNo;
//支付宝应用编号,此应用必须签约 APP支付
private string appid = "";
//应用的私钥
private string appPrivateKey = "";
//应用的支付宝公钥
private string aliPublicKey = "";
//阿里支付网关
private string aliOpenAPI = "https://openapi.alipay.com/gateway.do";
private void btnOutOrder_Press(object sender, EventArgs e)
{
tradeNo = "SMOAPP" + DateTime.Now.ToString("yyyyMMddHHmmss");
this.labOutOrder.Text = tradeNo;
}
private void btnCreateOrder_Press(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(tradeNo) == true)
{
btnOutOrder_Press(null, null);
}
IAopClient client = GetAPOClient();
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.Body = "请支持0.01元"; //支付描述
model.Subject = "支付"; //支付标题
model.TotalAmount = "0.01"; //支付金额
model.ProductCode = "QUICK_MSECURITY_PAY"; //产品码
model.OutTradeNo = tradeNo; //外部编号,外部编号在支付成功时,只能使用一次
model.TimeoutExpress = "30m"; //超时时间
request.SetBizModel(model);
//有条件可设置回调地址,支付宝在支付完成后会POST此地址。或通过查询的方式。
//request.SetNotifyUrl("");
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse response = client.SdkExecute(request);
//页面输出的response.Body就是orderString 可以直接给客户端请求,无需再做处理。
System.Diagnostics.Debug.WriteLine(response.Body);
//注意,第一个参数是苹果支付需要的格式为ap应用编号,android可设置为空
this.aliPay1.AppPay("ap" + appid, response.Body, (obj, args) =>
{
if (args.isError == true)
{
MessageBox.Show(args.error);
}
else
{
string result = "";
//foreach (KeyValuePair item in args.result)
//{
// result += string.Format("{0}/{1}" + Environment.NewLine, item.Key, item.Value);
//}
MessageBox.Show(result);
}
});
}
private void btnOrderStatus_Press(object sender, EventArgs e)
{
IAopClient client = GetAPOClient();
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
model.OutTradeNo = tradeNo;
request.SetBizModel(model);
//这是普通的接口使用Execute
AlipayTradeQueryResponse response = client.Execute(request);
//页面输出的response.Body就是orderString 可以直接给客户端请求,无需再做处理。
System.Diagnostics.Debug.WriteLine(response.Body);
MessageBox.Show(response.Body);
}
private IAopClient GetAPOClient()
{
return new DefaultAopClient(aliOpenAPI, appid, appPrivateKey, "json", "1.0", "RSA2", aliPublicKey, "utf-8", false);
}
}
}
using System;
using Smobiler.Core;
namespace Smobiler.Tutorials.Plugins
{
partial class demoAliPay : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.title1 = new Smobiler.Core.Controls.Title();
this.btnCreateOrder = new Smobiler.Core.Controls.Button();
this.btnOrderStatus = new Smobiler.Core.Controls.Button();
this.btnOutOrder = new Smobiler.Core.Controls.Button();
this.labOutOrder = new Smobiler.Core.Controls.Label();
this.aliPay1 = new Smobiler.Plugins.AliPay();
//
// title1
//
this.title1.ImageType = Smobiler.Core.Controls.ImageEx.ImageStyle.FontIcon;
this.title1.Name = "title1";
this.title1.ResourceID = "angle-left";
this.title1.Size = new System.Drawing.Size(300, 30);
this.title1.Text = "AliPay";
this.title1.ImagePress += new System.EventHandler(this.title1_ImagePress);
//
// btnCreateOrder
//
this.btnCreateOrder.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(192)))), ((int)(((byte)(78)))));
this.btnCreateOrder.Location = new System.Drawing.Point(24, 134);
this.btnCreateOrder.Name = "btnCreateOrder";
this.btnCreateOrder.Size = new System.Drawing.Size(100, 30);
this.btnCreateOrder.Text = "创建订单";
this.btnCreateOrder.Press += new System.EventHandler(this.btnCreateOrder_Press);
//
// btnOrderStatus
//
this.btnOrderStatus.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(67)))), ((int)(((byte)(81)))));
this.btnOrderStatus.Location = new System.Drawing.Point(142, 134);
this.btnOrderStatus.Name = "btnOrderStatus";
this.btnOrderStatus.Size = new System.Drawing.Size(100, 30);
this.btnOrderStatus.Text = "支付状态查询";
this.btnOrderStatus.Press += new System.EventHandler(this.btnOrderStatus_Press);
//
// btnOutOrder
//
this.btnOutOrder.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(176)))), ((int)(((byte)(249)))));
this.btnOutOrder.BorderRadius = 0;
this.btnOutOrder.FontSize = 15F;
this.btnOutOrder.Location = new System.Drawing.Point(0, 66);
this.btnOutOrder.Name = "btnOutOrder";
this.btnOutOrder.Size = new System.Drawing.Size(100, 35);
this.btnOutOrder.Text = "生成订单编号";
this.btnOutOrder.Press += new System.EventHandler(this.btnOutOrder_Press);
//
// labOutOrder
//
this.labOutOrder.FontSize = 15F;
this.labOutOrder.Location = new System.Drawing.Point(100, 66);
this.labOutOrder.Name = "labOutOrder";
this.labOutOrder.Size = new System.Drawing.Size(200, 35);
this.labOutOrder.Text = "[外部订单]";
//
// aliPay1
//
this.aliPay1.Name = "aliPay1";
//
// demoAliPay
//
this.Components.AddRange(new Smobiler.Core.Controls.MobileComponent[] {
this.aliPay1});
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.btnCreateOrder,
this.btnOrderStatus,
this.btnOutOrder,
this.labOutOrder});
this.Name = "demoAliPay";
}
#endregion
private Core.Controls.Title title1;
private Core.Controls.Button btnCreateOrder;
private Core.Controls.Button btnOrderStatus;
private Core.Controls.Button btnOutOrder;
private Core.Controls.Label labOutOrder;
private Smobiler.Plugins.AliPay aliPay1;
}
}