ToB企服应用市场:ToB评测及商务社交产业平台

标题: .net6 使用Senparc开发小程序配置 [打印本页]

作者: 尚未崩坏    时间: 2022-8-26 21:32
标题: .net6 使用Senparc开发小程序配置
1.添加引用

 
 
 
2.添加配置文件
  1. /// <summary>
  2.     /// 微信
  3.     /// </summary>
  4.     public class WeChat
  5.     {
  6.         // 小程序
  7.         public string WxOpenAppId { get; set; }
  8.         public string WxOpenAppSecret { get; set; }
  9.         //// 微信支付
  10.         //public string TenPayV3_AppId { get; set; }
  11.         //public string TenPayV3_AppSecret { get; set; }
  12.         //public string TenPayV3_MchId { get; set; }
  13.         //public string TenPayV3_Key { get; set; }
  14.         //public string TenPayV3_CertPath { get; set; }
  15.         //public string TenPayV3_CertSecret { get; set; }
  16.         //public string TenPayV3_TenpayNotify { get; set; }
  17.         //public string TenPayV3_RechargeTenpayNotify { get; set; }
  18.         //public string TenPayV3_RefundNotify { get; set; }
  19.         //public string TenPayV3_RechargeRefundNotify { get; set; }
  20.         //public string TenPayV3_WxOpenTenpayNotify { get; set; }
  21.         /// <summary>
  22.         /// 是否是开发环境
  23.         /// </summary>
  24.         public string IsDevelopment { get; set; }
  25.     }
复制代码
 
3.在appsetting.jso里面配置参数
  1. "WeChat": {
  2.     // 小程序
  3.     "WxOpenAppId": "",
  4.     "WxOpenAppSecret": ""
  5.     ////微信支付
  6.     //"TenPayV3_AppId": "", //商户平台绑定了微信小程序就可以直接用这个
  7.     //"TenPayV3_AppSecret": "", //商户平台绑定了微信小程序就可以直接用这个
  8.     //"TenPayV3_MchId": "", //
  9.     //"TenPayV3_Key": "", //
  10.     //"TenPayV3_CertPath": "", //(新)支付证书物理路径,如:D:\\cert\\apiclient_cert.p12
  11.     //"TenPayV3_CertSecret": "", //(新)支付证书密码(原始密码和 MchId 相同)
  12.     //"TenPayV3_TenpayNotify": "https://river.runtoinfo.com/agr/api/TenPayV3/PayNotifyUrl",
  13.     ////http://YourDomainName/TenpayV3/PayNotifyUrl
  14.     ////如果不设置TenPayV3_WxOpenTenpayNotify,默认在 TenPayV3_TenpayNotify 的值最后加上 "WxOpen"
  15.     //"TenPayV3_WxOpenTenpayNotify": "https://river.runtoinfo.com/agr/api/TenPayV3/PayNotifyUrlWxOpen" //http://YourDomainName/TenpayV3/PayNotifyUrlWxOpen
  16.   }
复制代码
 
4.配置program
  1. [/code]
  2. builder.Services.AddMemoryCache();
  3. [code]<br>//微信
  4. builder.Services.AddSenparcGlobalServices(builder.Configuration)//Senparc.CO2NET 全局注册
  5.                    .AddSenparcWeixinServices(builder.Configuration);//Senparc.Weixin 注册
  6.                                                                     //添加 微信支付api证书
  7.                                                                     //var mac_id = builder.Configuration["WeChat:TenPayV3_MchId"];
  8.                                                                     //builder.Services.AddCertHttpClient(mac_id + "_", mac_id, AppDomain.CurrentDomain.BaseDirectory + "/wwwroot/" + builder.Configuration["WeChat:TenPayV3_CertPath"]);
  9. var senparcSetting = builder.Services.BuildServiceProvider().GetRequiredService<IOptions<SenparcSetting>>();
  10. IRegisterService register = RegisterService.Start(senparcSetting.Value).UseSenparcGlobal();// 启动 CO2NET 全局注册,必须!
  11. var senparcWeixinSetting = builder.Services.BuildServiceProvider().GetRequiredService<IOptions<SenparcWeixinSetting>>();
  12. //register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);//微信全局注册,必须!
  13. register.UseSenparcWeixin(senparcWeixinSetting.Value, weixinRegister =>
  14. {
  15.     #region 微信相关配置
  16.     /* 微信配置开始
  17.     *
  18.     * 建议按照以下顺序进行注册,尤其须将缓存放在第一位!
  19.     */
  20.     #region 微信缓存(按需,必须放在配置开头,以确保其他可能依赖到缓存的注册过程使用正确的配置)
  21.     //注意:如果使用非本地缓存,而不执行本块注册代码,将会收到“当前扩展缓存策略没有进行注册”的异常
  22.     // DPBMARK_END
  23.     // 微信的 Memcached 缓存,如果不使用则注释掉(开启前必须保证配置有效,否则会抛错)    -- DPBMARK Memcached
  24.     //if (UseMemcached(senparcSetting.Value, out _))
  25.     //{
  26.     //    app.UseEnyimMemcached();
  27.     //    weixinRegister.UseSenparcWeixinCacheMemcached();
  28.     //}                                                                                     // DPBMARK_END
  29.     #endregion
  30.     /* 微信配置结束 */
  31.     #endregion
  32. });//微信全局注册,必须!
  33. //注册 Token容器 应用凭证
  34. var con = AccessTokenContainer.RegisterAsync(builder.Configuration["WeChat:WxOpenAppId"], builder.Configuration["WeChat:WxOpenAppSecret"]);
  35. con.Wait();<br>
复制代码
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4