網站首頁 編程語言 正文
1.添加引用
2.添加配置文件
/// <summary>
/// 微信
/// </summary>
public class WeChat
{
// 小程序
public string WxOpenAppId { get; set; }
public string WxOpenAppSecret { get; set; }
//// 微信支付
//public string TenPayV3_AppId { get; set; }
//public string TenPayV3_AppSecret { get; set; }
//public string TenPayV3_MchId { get; set; }
//public string TenPayV3_Key { get; set; }
//public string TenPayV3_CertPath { get; set; }
//public string TenPayV3_CertSecret { get; set; }
//public string TenPayV3_TenpayNotify { get; set; }
//public string TenPayV3_RechargeTenpayNotify { get; set; }
//public string TenPayV3_RefundNotify { get; set; }
//public string TenPayV3_RechargeRefundNotify { get; set; }
//public string TenPayV3_WxOpenTenpayNotify { get; set; }
/// <summary>
/// 是否是開發環境
/// </summary>
public string IsDevelopment { get; set; }
}
3.在appsetting.jso里面配置參數
"WeChat": {
// 小程序
"WxOpenAppId": "",
"WxOpenAppSecret": ""
////微信支付
//"TenPayV3_AppId": "", //商戶平臺綁定了微信小程序就可以直接用這個
//"TenPayV3_AppSecret": "", //商戶平臺綁定了微信小程序就可以直接用這個
//"TenPayV3_MchId": "", //
//"TenPayV3_Key": "", //
//"TenPayV3_CertPath": "", //(新)支付證書物理路徑,如:D:\\cert\\apiclient_cert.p12
//"TenPayV3_CertSecret": "", //(新)支付證書密碼(原始密碼和 MchId 相同)
//"TenPayV3_TenpayNotify": "https://river.runtoinfo.com/agr/api/TenPayV3/PayNotifyUrl",
////http://YourDomainName/TenpayV3/PayNotifyUrl
////如果不設置TenPayV3_WxOpenTenpayNotify,默認在 TenPayV3_TenpayNotify 的值最后加上 "WxOpen"
//"TenPayV3_WxOpenTenpayNotify": "https://river.runtoinfo.com/agr/api/TenPayV3/PayNotifyUrlWxOpen" //http://YourDomainName/TenpayV3/PayNotifyUrlWxOpen
}
4.配置program
builder.Services.AddMemoryCache();
builder.Services.AddMemoryCache();
//微信
builder.Services.AddSenparcGlobalServices(builder.Configuration)//Senparc.CO2NET 全局注冊
.AddSenparcWeixinServices(builder.Configuration);//Senparc.Weixin 注冊
//添加 微信支付api證書
//var mac_id = builder.Configuration["WeChat:TenPayV3_MchId"];
//builder.Services.AddCertHttpClient(mac_id + "_", mac_id, AppDomain.CurrentDomain.BaseDirectory + "/wwwroot/" + builder.Configuration["WeChat:TenPayV3_CertPath"]);
var senparcSetting = builder.Services.BuildServiceProvider().GetRequiredService<IOptions<SenparcSetting>>();
IRegisterService register = RegisterService.Start(senparcSetting.Value).UseSenparcGlobal();// 啟動 CO2NET 全局注冊,必須!
var senparcWeixinSetting = builder.Services.BuildServiceProvider().GetRequiredService<IOptions<SenparcWeixinSetting>>();
//register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);//微信全局注冊,必須!
register.UseSenparcWeixin(senparcWeixinSetting.Value, weixinRegister =>
{
#region 微信相關配置
/* 微信配置開始
*
* 建議按照以下順序進行注冊,尤其須將緩存放在第一位!
*/
#region 微信緩存(按需,必須放在配置開頭,以確保其他可能依賴到緩存的注冊過程使用正確的配置)
//注意:如果使用非本地緩存,而不執行本塊注冊代碼,將會收到“當前擴展緩存策略沒有進行注冊”的異常
// DPBMARK_END
// 微信的 Memcached 緩存,如果不使用則注釋掉(開啟前必須保證配置有效,否則會拋錯) -- DPBMARK Memcached
//if (UseMemcached(senparcSetting.Value, out _))
//{
// app.UseEnyimMemcached();
// weixinRegister.UseSenparcWeixinCacheMemcached();
//} // DPBMARK_END
#endregion
/* 微信配置結束 */
#endregion
});//微信全局注冊,必須!
//注冊 Token容器 應用憑證
var con = AccessTokenContainer.RegisterAsync(builder.Configuration["WeChat:WxOpenAppId"], builder.Configuration["WeChat:WxOpenAppSecret"]);
con.Wait();
原文鏈接:https://www.cnblogs.com/kangsir7/archive/2022/07/14/16476463.html
相關推薦
- 2022-09-17 python生成requirements.txt文件的推薦方法_python
- 2022-11-12 PostgreSQL邏輯復制解密原理解析_PostgreSQL
- 2022-12-15 詳解C#中HttpClient的用法及相關問題的解決方法_C#教程
- 2022-09-05 springboot是怎么實現自動配置的?
- 2023-02-15 Python進行ffmpeg推流和拉流rtsp、rtmp實例詳解_python
- 2022-04-16 C++中函數匹配機制詳解_C 語言
- 2022-05-25 Starship定制shell提示符實現信息自由_python
- 2022-01-31 有關“數據統計”的一些概念 -- PV UV VV IP跳出率等
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支