您的位置:首页 > 运维架构 > 网站架构

支付宝手机网站接口对接

2017-03-16 17:58 316 查看
手机网站支付接口,请参考支付宝官方文档:https://b.alipay.com/signing/productSet.htm?navKey=all

1.需要提供应用ID、应用私钥、支付宝公钥

2.代码实现:

下载官方SDK,并编译引用到项目中去。

初始化对象:private readonly IAopClient _client= new DefaultAopClient("https://openapi.alipay.com/gateway.do", "应用ID", "应用私钥", "json", "1.0", "签名类型", "支付宝公钥", "字符编码格式,支持GBK和UTF-8", false);

支付接口:

1>调用支付宝支付网关

/// <summary>
/// 查询订单在支付宝的状态
/// </summary>
/// <param name="queryOrderRequest"></param>
/// <returns></returns>
private bool AlipayTradeWapQuery(订单查询实体 queryOrder)
{
var result = false;
if (queryOrder == null)
{
Log.Error(this.GetType().ToString(), "查询数据不能为空");
return result;
}

Log.Info(this.GetType().ToString(), "AlipayTradeWapQuery Start......");
string responseText = string.Empty;
try
{
#region 调用支付宝支付查询接口

AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
request.BizContent = "{" +
"    \"out_trade_no\":\"" + queryOrder.订单编号 + "\"," +
"    \"trade_no\":\"" + queryOrder.交易号 + "\"" +
"  }";
AlipayTradeQueryResponse response = _client.Execute(request);
string tradeStatus = response.TradeStatus;
responseText = tradeStatus;
if (tradeStatus == "TRADE_SUCCESS" || tradeStatus == "TRADE_CLOSED" || tradeStatus == "TRADE_FINISHED")
{
//处理支付业务
result=true;
Log.Info(this.GetType().ToString(), "支付成功");
}
else
{
Log.Info(this.GetType().ToString(), "支付失败");
}
#endregion
}
catch (Exception ex)
{
responseText = ex.Message;
Log.Error(this.GetType().ToString(), "Exception: " + ex.Message);
}
Log.Debug(this.GetType().ToString(), string.Format("支付宝手机网站支付查询跟踪信息。GetForm:{0}", responseText);
Log.Info(this.GetType().ToString(), "AlipayTradeWapQuery End......");

return result;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: