Skip to content

Commit 552b7ee

Browse files
author
chengliangzhang
committed
新增签约接口;微信小程序获取 openid 方法
1 parent 3c78db3 commit 552b7ee

File tree

13 files changed

+264
-3
lines changed

13 files changed

+264
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# ChangeLog
2+
### 1.4.5
3+
- 新增
4+
- 新增签约接口
5+
- 新增微信小程序获取openid方法
6+
27
### 1.4.4
38
- 修改
49
- order创建示例参数新增 余额结算信息

Example/Entry.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private static void Main(string[] args)
4646
private static void Examples(string appId)
4747
{
4848
ChargeDemo.Example(appId);
49+
AgreementDemo.Example(appId);
4950
RedEnvelopeDemo.Example(appId);
5051
TransferDemo.Example(appId);
5152
VerifyDemo.Example();

Example/Example.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
</ItemGroup>
5050
<ItemGroup>
5151
<Compile Include="Entry.cs" />
52+
<Compile Include="Example\AgreementDemo.cs" />
5253
<Compile Include="Example\BalanceBonusDemo.cs" />
5354
<Compile Include="Example\BalanceSettlementDemo.cs" />
5455
<Compile Include="Example\BalanceTransactionDemo.cs" />
@@ -59,7 +60,7 @@
5960
<Compile Include="Example\RoyaltyDemo.cs" />
6061
<Compile Include="Example\RoyaltySettlementDemo.cs" />
6162
<Compile Include="Example\RoyaltyTemplateDemo.cs" />
62-
<Compile Include="Example\RoyaltyTransactionDemo.cs" />
63+
<Compile Include="Example\RoyaltyTransactionDemo.cs" />
6364
<Compile Include="Example\SettleAccountDemo.cs" />
6465
<Compile Include="Example\SubAppDemo.cs" />
6566
<Compile Include="Example\BatchRefundDemo.cs" />

Example/Example/AgreementDemo.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Pingpp;
4+
using Pingpp.Models;
5+
6+
namespace Example.Example
7+
{
8+
internal class AgreementDemo
9+
{
10+
/// <summary>
11+
/// 本示例只介绍如何请求支付凭据(charge 对象),以及如何查询指定 charge 对象和 charge 列表,
12+
/// 至于如何将 charge 对象传递给客户端需要接入者自行处理
13+
/// </summary>
14+
public static void Example(string appId)
15+
{
16+
17+
Console.WriteLine("**** 创建签约示例 ****");
18+
var param = new Dictionary<string, object> {
19+
{"app", appId},
20+
{"contract_no", randomStr(10)},
21+
{"channel", "qpay"},
22+
{"extra", new Dictionary<string, object>{
23+
{"display_account", "签约测试"}
24+
}},
25+
{"metadata", new Dictionary<string, object>{}}
26+
};
27+
28+
var agreement = Agreement.Create(param);
29+
Console.WriteLine(agreement);
30+
Console.WriteLine();
31+
32+
Console.WriteLine("****查询 agreement 对象****");
33+
Console.WriteLine(Agreement.Retrieve(agreement.Id));
34+
Console.WriteLine();
35+
36+
Console.WriteLine("****解除签约 agreement 对象****");
37+
Console.WriteLine(Agreement.Cancel(agreement.Id));
38+
Console.WriteLine();
39+
40+
41+
Console.WriteLine("****查询 agreement 列表****");
42+
Dictionary<string, object> listParams = new Dictionary<string, object>{
43+
{"app", appId}, // 必填 签约使用的 app id
44+
{"per_page", 10}, //限制有多少对象可以被返回,限制范围是从 1-100 项,默认是 10 项。
45+
};
46+
Console.WriteLine(Agreement.List(listParams));
47+
}
48+
49+
public static String randomStr(int length)
50+
{
51+
string result = "";
52+
System.Random random = new Random();
53+
for (int i = 0; i < length; i++)
54+
{
55+
result += random.Next(10).ToString();
56+
}
57+
return result;
58+
}
59+
}
60+
}

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,33 @@ CardInfo.Query(List<string> params)
657657
```
658658

659659
详细信息请参考 [API 文档](https://pingxx.com/document/api)
660+
661+
### 创建签约
662+
```c#
663+
Agreement.Create( Dictionary<string, object> createParams)
664+
```
665+
666+
### 查询签约状态
667+
```c#
668+
Agreement.Retrieve(string Id)
669+
```
670+
671+
### 解除签约
672+
```c#
673+
Agreement.Cancel(string Id)
674+
```
675+
676+
### 查询签约列表
677+
```c#
678+
Agreement.List( Dictionary<string, object> listParams)
679+
```
680+
681+
### 微信公众号获取openid
682+
```c#
683+
WxPubUtils.GetOpenId(string appId, string appSecret, string code)
684+
```
685+
686+
### 微信小程序获取openid
687+
```c#
688+
WxPubUtils.GetWxLiteOpenId(string appId, string appSecret, string code)
689+
```

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.4
1+
1.4.5

libs/pingpp.dll

3.5 KB
Binary file not shown.

pingpp/Models/Agreement.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Pingpp.Net;
5+
using Pingpp.Exception;
6+
7+
namespace Pingpp.Models
8+
{
9+
/// <summary>
10+
/// 签约对象
11+
/// </summary>
12+
public class Agreement :Pingpp
13+
{
14+
[JsonProperty("id")]
15+
public string Id { get; set; }
16+
[JsonProperty("object")]
17+
public string Object { get; set; }
18+
[JsonProperty("livemode")]
19+
public bool Livemode { get; set; }
20+
[JsonProperty("app")]
21+
public string App { get; set; }
22+
[JsonProperty("created")]
23+
public int? Created { get; set; }
24+
[JsonProperty("channel")]
25+
public string Channel { get; set; }
26+
[JsonProperty("contract_no")]
27+
public string ContractNo { get; set; }
28+
[JsonProperty("contract_id")]
29+
public string ContractId { get; set; }
30+
[JsonProperty("credential")]
31+
public Dictionary<string, object> Credential { get; set; }
32+
[JsonProperty("status")]
33+
public string Status { get; set; }
34+
[JsonProperty("time_succeeded")]
35+
public int? TimeSucceeded { get; set; }
36+
[JsonProperty("time_canceled")]
37+
public int? TImeCanceled { get; set; }
38+
[JsonProperty("failure_code")]
39+
public string FailureCode { get; set; }
40+
[JsonProperty("failure_msg")]
41+
public string FailureMsg { get; set; }
42+
[JsonProperty("metadata")]
43+
public Dictionary<string, object> Metadata { get; set; }
44+
[JsonProperty("extra")]
45+
public Dictionary<string, object> Extra { get; set; }
46+
47+
private const string BaseUrl = "/v1/agreements";
48+
49+
/// <summary>
50+
/// 创建签约接口
51+
/// </summary>
52+
/// <param name="param"></param>
53+
/// <returns></returns>
54+
public static Agreement Create(Dictionary<string, object> param)
55+
{
56+
var agreement = Requestor.DoRequest(BaseUrl, "POST", param);
57+
return Mapper<Agreement>.MapFromJson(agreement);
58+
}
59+
60+
/// <summary>
61+
/// 查询签约对象
62+
/// </summary>
63+
/// <param name="Id"></param>
64+
/// <returns></returns>
65+
public static Agreement Retrieve(string Id)
66+
{
67+
var agreement = Requestor.DoRequest(string.Format("{0}/{1}", BaseUrl, Id), "GET");
68+
return Mapper<Agreement>.MapFromJson(agreement);
69+
}
70+
71+
/// <summary>
72+
/// 解除签约
73+
/// </summary>
74+
/// <param name="Id"></param>
75+
/// <returns></returns>
76+
public static Agreement Cancel(string Id)
77+
{
78+
Dictionary<string, object> param = new Dictionary<string, object> {{ "status", "canceled" }};
79+
var agreement = Requestor.DoRequest(string.Format("{0}/{1}", BaseUrl, Id), "PUT", param);
80+
return Mapper<Agreement>.MapFromJson(agreement);
81+
}
82+
83+
/// <summary>
84+
/// 查询签约对象列表
85+
/// </summary>
86+
/// <param name="listParams"></param>
87+
/// <returns></returns>
88+
public static AgreementList List(Dictionary<string, object> listParams)
89+
{
90+
var agreementList = Requestor.DoRequest(Requestor.FormatUrl(BaseUrl, Requestor.CreateQuery(listParams)), "GET");
91+
return Mapper<AgreementList>.MapFromJson(agreementList);
92+
}
93+
}
94+
}

pingpp/Models/AgreementList.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace Pingpp.Models
6+
{
7+
public class AgreementList : Pingpp
8+
{
9+
[JsonProperty("object")]
10+
public string Object { get; set; }
11+
[JsonProperty("url")]
12+
public string Url { get; set; }
13+
[JsonProperty("has_more")]
14+
public bool HasMore { get; set; }
15+
[JsonProperty("data")]
16+
public IEnumerable<Agreement> Data { get; set; }
17+
}
18+
}

pingpp/Pingpp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class Pingpp
1010
public static volatile string ApiVersion;
1111
public static volatile string AcceptLanguage = "zh-CN";
1212
public static volatile string ApiBase = "https://api.pingxx.com";
13-
public static volatile string Version = "1.4.4";
13+
public static volatile string Version = "1.4.5";
1414
public static volatile bool BadGateWayMatch = true;
1515
public static volatile int MaxNetworkRetries = 1;
1616
protected static volatile int MaxRetry = 0;

0 commit comments

Comments
 (0)