Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
tooclian committed Mar 23, 2024
1 parent ba08fa0 commit ae99bf1
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 145 deletions.
201 changes: 77 additions & 124 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

WeChat-Sdk 是微信接口的请求封装,涵盖公众号、小程序及支付接口,主要用于日常业务方便而编写,所以只实现了一些需要的接口。

> 郑重声明:拒绝白嫖,如果有对你有帮助请至少点亮`星星`
### 使用方式

#### 设置NuGet源(NuGet.config)
#### 设置 NuGet 源(NuGet.config)

```xml
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -41,28 +39,48 @@ dotnet add package WeChat.Pay
var services = new ServiceCollection();

// 1.1 添加必要的Medation服务
services.AddMedation()
.AddHttpClient();
services.AddMedation(config =>
{
config.AddHttpClient();

# 添加需要的服务配置
config.AddWeChatMp();
config.AddWeChatApplet();
config.AddWeChatPay();
});

services.Configure<WeChatMpOptions>(options =>
{
options.AppId = "";
options.Secret = "";
});

// 1.2 注册微信相关的一些必要服务
services.AddWeChat()
// .WithPay() // 用到支付接口须添加此项配置
;
services.Configure<WeChatAppletOptions>(options =>
{
options.AppId = "";
options.Secret = "";
});

services.Configure<WeChatPayOptions>(options =>
{
options.AppId = "";
options.Secret = "";
options.MchId = "";
options.TransactionNotifyUrl = ""; // 默认的支付通知地址。如果未设置,则请求接口时必须传入
options.RefundNotifyUrl = ""; // 默认的退款通知地址
options.Certificate = ""; // PI证书(.p12)。可为 证书文件路径 / 证书文件的Base64编码
options.CertificatePassword = ""; // API证书密码。 默认为商户号
options.V3Key = ""; // APIv3密钥
});

var serviceProvider = services.BuildServiceProvider();

// 2.使用
var sender = serviceProvider.GetRequiredService<ISender>();

// 2.1 获取 access_token
var accessTokenRequest = WeChatAccessTokenRequest();
var accessTokenRequest = Mp.AccessToken.ToRequest("<appid>","<secret>");

// 设置微信应用号和密钥
accessTokenRequest.Configure(options=>
{
options.AppId = "<appid>";
options.Secret = "<secret>";
})
var accessTokenResponse = await sender.Send(accessTokenRequest);

if (accessTokenResponse.IsSucceed())
Expand All @@ -71,115 +89,50 @@ if (accessTokenResponse.IsSucceed())
}

// 内置 access_token 存储器使用
var accessTokenStore = serviceProvider.GetRequiredService<IWeChatAccessTokenStore>();
var token = await accessTokenStore.GetAsync("<appid>","<secret>");
var accessTokenStore = serviceProvider.GetRequiredService<IWeChatMpAccessTokenStore>();
var token = await accessTokenStore.GetAsync();

// 内置 ticket 存储器使用
var ticketStore = serviceProvider.GetRequiredService<IWeChatTicketStore>();
var ticket= await ticketStore.GetAsync("<appid>","<secret>");
var ticketStore = serviceProvider.GetRequiredService<Mp.IWeChatMpTicketStore>();
var ticket= await ticketStore.GetAsync();

```

### 实现接口

#### WeChat

| 请求类 | 名称 | 更新日期 | 说明 |
|:------------------------ |:--------------------------------------------------------------------------------------------------------------------------------------- | --------- | --- |
| WeChatAccessTokenRequest | 微信请求接口凭证获取 [[文档](https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html)] | 2022年1月1日 | |
| WeChatDecryptRequest<> | 微信开放数据解密 | 2022年1月1日 | |
| WeChatTicketRequest | 微信票据获取 [[文档](https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Nontax_Bill/API_list.html#2.1%20%E8%8E%B7%E5%8F%96ticket)] | 2022年1月1日 | |

#### WeChat.Applet(小程序)

| 请求类 | 名称 | 名称2 | 更新日期 | 说明 |
|:--------------------------------------- |:--------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ---- | --- |
| WeChatAppletCode2SessionRequest | 登录凭证校验 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html)] | auth.code2Session | | |
| WeChatAppletSubscribeMessageSendRequest | 发送订阅消息 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html)] | subscribeMessage.send | | |
| WeChatAppletCreateWxaQrCodeRequest | 创建小程序二维码 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html)] | wxacode.createQRCode | | |
| WeChatAppletGetWxaCodeRequest | 获取小程序码 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.get.html)] | wxacode.get | | |
| WeChatAppletGetWxaCodeUnlimitRequest | 获取小程序码 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html)] | wxacode.getUnlimited | | |
| WeChatAppletGenerateSchemeRequest | 获取小程序 scheme 码 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html)] | urlscheme.generate | | |
| WeChatAppletGenerateUrlLinkRequest | 获取小程序 URL Link [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html)] | urllink.generate | | |
| WeChatAppletQuerySchemeRequest | 查询小程序 scheme 码 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.query.html)] | urlscheme.query | | |
| WeChatAppletQueryUrlLinkRequest | 查询小程序 url_link 配置 [[文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.query.html)] | urllink.query | | |

#### WeChat.Mp(公众号)

##### 微信卡券

| 请求类 | 名称 | 更新日期 | 说明 |
|:------------------------------------------ |:---------------------------------------------------------------------------------------------------------------------------- | ---- | --- |
| WeChatMpCardBatchGetRequest | 批量查询卡券Id [[文档](https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#3)] | | |
| ==>【Code】<== | | | |
| WeChatMpCardCodeCheckRequest | 核查code | | |
| WeChatMpCardCodeConsumeRequest | 核销Code | | |
| WeChatMpCardCodeDecryptRequest | 加密Code解码 | | |
| WeChatMpCardCodeDepositRequest | 导入code | | |
| WeChatMpCardCodeGetRequest | 查询Code | | |
| WeChatMpCardCodeGetDepositCountRequest | 查询导入code数目 | | |
| WeChatMpCardCodeUnavailableRequest | 设置卡券失效 | | |
| WeChatMpCardCodeUpdateRequest | 更改Code | | |
| | | | |
| WeChatMpCardCreateRequest | 创建卡券 | | |
| WeChatMpDataCubeGetCardBizuiInfoRequest | 拉取卡券概况数据 | | |
| WeChatMpDataCubeGetCardInfoRequest | 获取免费券数据 | | |
| WeChatMpDataCubeGetMemberCardDetailRequest | 拉取单张会员卡数据 | | |
| WeChatMpDataCubeGetMemberCardsInfoRequest | 拉取会员卡概况数据 | | |
| WeChatMpCardDeleteRequest | 删除卡券 | | |
| WeChatMpCardGetRequest | 获取卡券详情 | | |
| ==>【礼品卡】<== | | | |
| WeChatMpCardMaintainSetRequest | 下架礼品卡货架 | | |
| WeChatMpCardGiftPageAddRequest | 创建礼品卡货架 | | |
| WeChatMpCardGiftPageBatchGetRequest | 查询礼品卡货架列表 | | |
| WeChatMpCardGiftPageUpdateRequest | 修改礼品卡货架信息 | | |
| | | | |
| WeChatMpCardLandingPageRequest | 创建货架 | | |
| WeChatMpCardModifyStockRequest | 修改库存 | | |
| WeChatMpCardMpNewsGetHtmlRequest | 图文消息群发卡券内容 | | |
| WeChatMpCardPayCellSetRequest | 卡券设置买单 | | |
| WeChatMpCardQrcodeCreateRequest | 创建二维码 | | |
| WeChatMpCardSelfConsumeCellSetRequest | 设置自助核销 | | |
| WeChatMpCardUpdateRequest | 更改卡券信息 | | |
| WeChatMpCardUserGetCardListRequest | 获取用户已领取卡券 | | |

##### 素材管理

| 请求类 | 名称 | 更新日期 | 说明 |
|:----------------------------- |:--------------- | ---- | --- |
| WeChatMpMediaGetRequest | 获取临时素材 | | |
| WeChatMpMediaUploadImgRequest | 上传图文消息内的图片获取URL | | |

##### 基础消息能力

| 请求类 | 名称 | 更新日期 | 说明 |
|:--------------------------- |:------ | ---- | --- |
| WeChatMpTemplateSendRequest | 发送模板消息 | | |

##### 微信门店

| 请求类 | 名称 | 更新日期 | 说明 |
|:-------------------------- |:-------- | ---- | --- |
| WeChatMpPoiAddRequest | 创建门店 | | |
| WeChatMpPoiDeleteRequest | 删除门店 | | |
| WeChatMpPoiGetRequest | 查询门店信息 | | |
| WeChatMpPoiCategoryRequest | 获取门店类目 | | |
| WeChatMpPoiGetListRequest | 查询门店列表 | | |
| WeChatMpPoiUpdateRequest | 修改门店服务信息 | | |

#### WeChat.Pay(微信支付)

##### 商户版

| 请求类 | 名称 | 更新日期 | 说明 |
|:------------------------------------------- |:------------------- | ---- | --- |
| WeChatPayTransactionsAppRequest | App下单API | | |
| WeChatPayAppSdkRequest | App调起支付API 参数获取 | | |
| WeChatPayCertificatesRequest | 获取平台证书列表 | | |
| WeChatPayTransactionsOutTradeNoCloseRequest | 关单API | | |
| WeChatPayTransactionsH5Request | H5下单API | | |
| WeChatPayTransactionsJsapiRequest | JSAPI下单API | | |
| WeChatPayJsapiSdkRequest | JSAPI调起支付API 参数获取 | | |
| WeChatPayTransactionsNativeRequest | Native下单API | | |
| WeChatPayTransactionsIdRequest | 查询订单API - 微信支付订单号查询 | | |
| WeChatPayTransactionsOutTradeNoRequest | 查询订单API - 商户订单号查询 | | |
| WeChatPayNotifyRequest<> | 微信支付通知请求 | | |
#### 微信公众号实现接口

- AccessToken
- JsapiConfig (微信公众号配置获取)
- MediaGet
- MediaUploadImg
- Ticket

#### 微信小程序实现接口

- AccessToken
- CheckSession
- Code2Session
- CreateQRCode
- GenerateNFCScheme
- GenerateScheme
- GenerateShortLink
- GenerateUrlLink
- GetPaidUnionid
- GetPhoneNumber
- GetQRCode
- GetUnlimitedQRCode
- QueryScheme
- QueryUrlLink
- ResetSession

#### 微信支付实现接口(基于 3.0 版本)

- PlatformCertificate
- Refunds
- TransactionsApp
- TransactionsAppSdk
- TransactionsClose
- TransactionsH5
- TransactionsJsapi
- TransactionsJsapiSdk
- TransactionsNative
- TransactionsQuery
30 changes: 9 additions & 21 deletions src/WeChat.Pay/WeChatPayOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ public class WeChatPayOptions
/// </summary>
public string MchId { get; set; }

/// <summary>
/// 子商户应用号
/// 仅服务商使用
/// </summary>
public string SubAppId { get; set; }

/// <summary>
/// 子商户号
/// 仅服务商使用
/// </summary>
public string SubMchId { get; set; }

/// <summary>
/// 默认的支付通知地址。如果未设置,则请求接口时必须传入
/// </summary>
Expand Down Expand Up @@ -79,21 +67,21 @@ public string CertificatePassword
}
}

/// <summary>
/// API密钥
/// </summary>
public string Key { get; set; }
///// <summary>
///// API密钥
///// </summary>
//public string Key { get; set; }

/// <summary>
/// APIv3密钥
/// </summary>
public string V3Key { get; set; }

/// <summary>
/// RSA公钥
/// 目前仅调用"企业付款到银行卡API"时使用,执行"获取RSA加密公钥API"即可获取。
/// </summary>
public string RsaPublicKey { get; set; }
///// <summary>
///// RSA公钥
///// 目前仅调用"企业付款到银行卡API"时使用,执行"获取RSA加密公钥API"即可获取。
///// </summary>
//public string RsaPublicKey { get; set; }

///// <summary>
///// RSA私钥
Expand Down

0 comments on commit ae99bf1

Please sign in to comment.