# 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:
Notes:
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.builder.Services.AddSenparcWeixinServices(builder.Configuration)
is used to complete the registration of Senparc.Weixin.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");
The value of weixinSetting
comes from appsettings.json
by default:
"SenparcWeixinSetting": {
"IsDebug": true,
"Token": "#{Token}#",
"EncodingAESKey": "#{EncodingAESKey}#",
"WeixinAppId": "#{WeixinAppId}#",
"WeixinAppSecret": "#{WeixinAppSecret}#"
}
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
.