.net6?使用Senparc開發(fā)小程序配置過程
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>
/// 是否是開發(fā)環(huán)境
/// </summary>
public string IsDevelopment { get; set; }
}3.在appsetting.jso里面配置參數(shù)
"WeChat": {
// 小程序
"WxOpenAppId": "",
"WxOpenAppSecret": ""
////微信支付
//"TenPayV3_AppId": "", //商戶平臺(tái)綁定了微信小程序就可以直接用這個(gè)
//"TenPayV3_AppSecret": "", //商戶平臺(tái)綁定了微信小程序就可以直接用這個(gè)
//"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
////如果不設(shè)置TenPayV3_WxOpenTenpayNotify,默認(rèn)在 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 全局注冊(cè)
.AddSenparcWeixinServices(builder.Configuration);//Senparc.Weixin 注冊(cè)
//添加 微信支付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();// 啟動(dòng) CO2NET 全局注冊(cè),必須!
var senparcWeixinSetting = builder.Services.BuildServiceProvider().GetRequiredService<IOptions<SenparcWeixinSetting>>();
//register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);//微信全局注冊(cè),必須!
register.UseSenparcWeixin(senparcWeixinSetting.Value, weixinRegister =>
{
#region 微信相關(guān)配置
/* 微信配置開始
*
* 建議按照以下順序進(jìn)行注冊(cè),尤其須將緩存放在第一位!
*/
#region 微信緩存(按需,必須放在配置開頭,以確保其他可能依賴到緩存的注冊(cè)過程使用正確的配置)
//注意:如果使用非本地緩存,而不執(zhí)行本塊注冊(cè)代碼,將會(huì)收到“當(dāng)前擴(kuò)展緩存策略沒有進(jìn)行注冊(cè)”的異常
// DPBMARK_END
// 微信的 Memcached 緩存,如果不使用則注釋掉(開啟前必須保證配置有效,否則會(huì)拋錯(cuò)) -- DPBMARK Memcached
//if (UseMemcached(senparcSetting.Value, out _))
//{
// app.UseEnyimMemcached();
// weixinRegister.UseSenparcWeixinCacheMemcached();
//} // DPBMARK_END
#endregion
/* 微信配置結(jié)束 */
#endregion
});//微信全局注冊(cè),必須!
//注冊(cè) Token容器 應(yīng)用憑證
var con = AccessTokenContainer.RegisterAsync(builder.Configuration["WeChat:WxOpenAppId"], builder.Configuration["WeChat:WxOpenAppSecret"]);
con.Wait();到此這篇關(guān)于.net6 使用Senparc開發(fā)小程序配置的文章就介紹到這了,更多相關(guān).net6 開發(fā)小程序配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于ERP程序的公共代碼中出現(xiàn)的問題及過度封裝不方便維護(hù)的解決辦法
本篇文章介紹了,基于ERP程序的公共代碼中出現(xiàn)的問題及過度封裝不方便維護(hù)的解決辦法。需要的朋友參考下2013-05-05
AJAX使用post發(fā)送數(shù)據(jù)xml格式接受數(shù)據(jù)
AJAX使用post發(fā)送數(shù)據(jù)xml格式接受數(shù)據(jù),需要的朋友可以參考一下2013-03-03
ASP.NET中的跳轉(zhuǎn) 200, 301, 302轉(zhuǎn)向?qū)崿F(xiàn)代碼
跳轉(zhuǎn)非常常用,在哪里都一樣,這里的一些說明和用法也如此,不止適用于asp.net,其他語言也會(huì)用得到。跳轉(zhuǎn)的目的本來很簡(jiǎn)單,就是當(dāng)用戶或系統(tǒng)需要時(shí)從一個(gè)頁面轉(zhuǎn)向另一個(gè)頁面,但自從有了各種各樣的需求,還有那個(gè)什么SEO的東西之后,跳轉(zhuǎn)被搞得極其復(fù)雜2008-09-09
.NET Core 2.0遷移小技巧之web.config 配置文件示例詳解
這篇文章主要給大家介紹了關(guān)于.NET Core 2.0遷移技巧之web.config 配置文件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08
MVC使用極驗(yàn)驗(yàn)證制作登錄驗(yàn)證碼學(xué)習(xí)筆記7
這篇文章主要介紹了MVC使用極驗(yàn)驗(yàn)證制作登錄驗(yàn)證碼學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
asp.net 通用的連接數(shù)據(jù)庫(kù)實(shí)例代碼
數(shù)據(jù)庫(kù)連接是所有程序開發(fā)是會(huì)用到的,只是不同程序與數(shù)據(jù)庫(kù)連接的方法不一樣,下面我來介紹asp.net中數(shù)據(jù)庫(kù)連接代碼,有需要的朋友可以參考一下2013-08-08

