chengkun
2025-06-05 4080b5997b38ca84b3b203c7101dcadb97b76925
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using NUnit.Framework;
using Alipay.EasySDK.Factory;
using Alipay.EasySDK.Util.Generic.Models;
using System;
using System.Collections.Generic;
using Alipay.EasySDK.Kernel.Util;
 
namespace UnitTest.Util.Generic
{
    public class ClientTest
    {
        [SetUp]
        public void SetUp()
        {
            Factory.SetOptions(TestAccount.Mini.CONFIG);
        }
 
        [Test]
        public void TestExecuteWithoutAppAuthToken()
        {
            string outTradeNo = Guid.NewGuid().ToString();
            AlipayOpenApiGenericResponse response = Factory.Util.Generic().Execute(
                    "alipay.trade.create", null, GetBizParams(outTradeNo));
 
            Assert.IsTrue(ResponseChecker.Success(response));
            Assert.AreEqual(response.Code, "10000");
            Assert.AreEqual(response.Msg, "Success");
            Assert.IsNull(response.SubCode);
            Assert.IsNull(response.SubMsg);
            Assert.NotNull(response.HttpBody);
        }
 
        [Test]
        public void TestExecuteWithAppAuthToken()
        {
            string outTradeNo = Guid.NewGuid().ToString();
            AlipayOpenApiGenericResponse response = Factory.Util.Generic().Execute(
                    "alipay.trade.create", GetTextParams(), GetBizParams(outTradeNo));
 
            Assert.IsFalse(ResponseChecker.Success(response));
            Assert.AreEqual(response.Code, "20001");
            Assert.AreEqual(response.Msg, "Insufficient Token Permissions");
            Assert.AreEqual(response.SubCode, "aop.invalid-app-auth-token");
            Assert.AreEqual(response.SubMsg, "无效的应用授权令牌");
            Assert.NotNull(response.HttpBody);
        }
 
        private Dictionary<string, string> GetTextParams()
        {
            return new Dictionary<string, string>
            {
                { "app_auth_token", "201712BB_D0804adb2e743078d1822d536956X34" }
            };
 
        }
 
        private Dictionary<string, object> GetBizParams(string outTradeNo)
        {
            return new Dictionary<string, object>
            {
                { "subject", "Iphone6 16G" },
                { "out_trade_no", outTradeNo },
                { "total_amount", "0.10" },
                { "buyer_id", "2088002656718920" },
                { "extend_params", GetHuabeiParams() }
            };
 
        }
 
        private Dictionary<string, string> GetHuabeiParams()
        {
            return new Dictionary<string, string>
            {
                { "hb_fq_num", "3"},
                { "hb_fq_seller_percent", "3"}
            };
        }
    }
}