温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

.net6怎么使用Senparc开发小程序

发布时间:2022-07-14 13:47:03 来源:亿速云 阅读:197 作者:iii 栏目:开发技术

本篇内容介绍了“.net6怎么使用Senparc开发小程序”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

1.添加引用

.net6怎么使用Senparc开发小程序

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();

“.net6怎么使用Senparc开发小程序”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI