NewGaoKaoApi/PaymentSDK/AliPay/AliPayHelper.cs

36 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
using System;
using System.Collections.Generic;
using System.Text;
namespace PaymentSDK
{
public class AliPayHelper
{
public string UnifiedOrder(AlipayTradeAppPayModel alipay)
{
IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AliPayConfig.APP_ID, AliPayConfig.APP_PRIVATE_KEY, "json", "1.0", "RSA2", AliPayConfig.ALIPAY_PUBLIC_KEY, AliPayConfig.CHARSET, false);
// 实 例 化 具 体 API 对 应 的 request 类 , 类 名 称 和 接 口 名 称 对 应 , 当 前 调 用 接 口 名 称 如 alipay .trade .app .pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
// SDK 已 经 封 装 掉 了 公 共 参 数 这 里 只 需 要 传 入 业 务 参 数 。 以 下 方 法 为 sdk 的 model 入 参 方 式 ( model 和 biz_content 同 时 存 在 的 情 况 下 取 biz_content ) 。
request.SetBizModel(alipay);
request.SetNotifyUrl(AliPayConfig.NotifyUrl);
// 这 里 和 普 通 的 接 口 调 用 不 同 使 用 的 是 sdkExecute
AlipayTradeAppPayResponse response = client.SdkExecute(request);
// HttpUtility .HtmlEncode 是 为 了 输 出 到 页 面 时 防 止 被 浏 览 器 将 关 键 参 数 html 转 义 实 际 打 印 到 日 志 以 及 http 传 输 不 会 有 这 个 问 题
// 页 面 输 出 的 response .Body 就 是 orderString 可 以 直 接 给 客 户 端 请 求 无 需 再 做 处 理 。
return response.Body;
}
}
}