# Registration

# Global Registration

The registration process for all Senparc.Weixin SDKs is similar.

First, complete the overall registration code for all Senparc.Weixin SDKs. Add the following code in Program.cs:

Register Senparc.Weixin

Notes:

  1. builder.Services.AddMemoryCache() Senparc.Weixin supports multiple cache strategies like native cache, Redis, Memcached etc. By default native cache is used, so it needs to be enabled here.

  2. builder.Services.AddSenparcWeixinServices(builder.Configuration) is used to complete the registration of Senparc.Weixin.

  3. app.UseSenparcWeixin() method is used to configure and enable Senparc.Weixin.

The above code is the same for all Senparc.Weixin sub-modules, and only 3 lines are needed.

Reference file for this project:

/Program.cs

# Official Account Registration

Insert the following code in the delegate method on line 17 of the above code to complete the default official account registration:

register.RegisterMpAccount(weixinSetting, "[Senparc Network Assistant]Official Account");

Register WeChat Official Account

The value of weixinSetting comes from appsettings.json by default:

  "SenparcWeixinSetting": {
    "IsDebug": true,

    "Token": "#{Token}#",
    "EncodingAESKey": "#{EncodingAESKey}#",
    "WeixinAppId": "#{WeixinAppId}#",
    "WeixinAppSecret": "#{WeixinAppSecret}#"
  }

Configuration Parameters

Where Token, EncodingAESKey, WeixinAppId and WeixinAppSecret correspond to the configuration parameters in the WeChat Official Account backend.

Reference file for this project:

/appsettings.json

Configuration is complete.

Tip: The registered information can be obtained through Senparc.Weixin.Config.SenparcWeixinSetting.