{"record":{"id":"deb90914fcbc23a7","repo":"JeffreySu/WeiXinMPSDK","slug":"chainbrandprofitsharingapis","errorCode":null,"errorMessage":"未获取到用于加密分账接收方姓名的微信支付公钥或平台证书。","messagePattern":"未获取到用于加密分账接收方姓名的微信支付公钥或平台证书。","errorType":"exception","errorClass":"TenpayApiRequestException","httpStatus":null,"severity":"critical","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/ChainBrandProfitsharing/ChainBrandProfitsharingApis.cs","lineNumber":342,"sourceCode":"                .Where(target => target != null)\n                .ToArray() ?? Array.Empty<object>();\n            if (targetList.Length == 0)\n            {\n                return new TenPayApiRequest(_setting);\n            }\n\n            var publicKey = GetConfiguredPaymentPublicKey();\n            if (string.IsNullOrWhiteSpace(publicKey.Key))\n            {\n                var publicKeys = await new BasePayApis(_setting)\n                    .GetPublicKeysAsync().ConfigureAwait(false);\n                publicKey = SelectPublicKey(publicKeys);\n            }\n\n            if (string.IsNullOrWhiteSpace(publicKey.Key) ||\n                string.IsNullOrWhiteSpace(publicKey.Value))\n            {\n                throw new TenpayApiRequestException(\n                    \"未获取到用于加密分账接收方姓名的微信支付公钥或平台证书。\");\n            }\n\n            foreach (var target in targetList)\n            {\n                SecurityHelper.FieldEncrypt(target, publicKey.Value,\n                    _setting.EncryptionType.Value,\n                    _setting.TenPayV3_TenPayPubKeyEnable);\n            }\n\n            return new TenPayApiRequest(_setting, httpClient =>\n            {\n                httpClient.DefaultRequestHeaders.Add(\"Wechatpay-Serial\",\n                    publicKey.Key);\n            });\n        }\n\n        private KeyValuePair<string, string>","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/ChainBrandProfitsharing/ChainBrandProfitsharingApis.cs#L324-L360","documentation":"Before serializing receivers, CreateSensitiveRequestAsync must encrypt receiver names with WeChat Pay's public key or platform certificate. When the resolved publicKey key/value is null or whitespace — i.e. no public key or platform certificate is available from configuration — TenpayApiRequestException is thrown.","triggerScenarios":"Calling AddReceiverAsync/CreateOrderAsync (which route through CreateSensitiveRequestAsync) when the TenpayV3Setting lacks WechatPayPublicKey or platform certificate configuration, or certificate download/refresh failed so the certificate store is empty.","commonSituations":"New WeChat merchants configured with public-key mode but the public key ID/value not filled in; certificate files not deployed to the server; SDK not refreshed certificates after rotation; switching between public-key and platform-certificate modes without updating config.","solutions":["Configure the WeChat Pay public key (public key ID + key content) in TenpayV3Setting, or ensure the platform certificate is downloaded and available.","Verify certificate files exist on disk and are readable by the app process.","Re-trigger certificate/platform-cert refresh after key rotation, then retry the request."],"exampleFix":"// before\nvar setting = new TenpayV3SenparcWeixinSetting { AppId = appId, MchId = mchId, Secret = secret }; // no key material\n// after\nvar setting = new TenpayV3SenparcWeixinSetting {\n    AppId = appId, MchId = mchId, Secret = secret,\n    TenPayV3_PublicKey = pubKeyValue, TenPayV3_PublicKeyId = pubKeyId\n};","handlingStrategy":"try-catch","validationCode":"var setting = Config.SenparcWeixinSetting.TenpayV3Setting;\nbool keyReady = !string.IsNullOrWhiteSpace(setting.TenPayV3_PublicKey) || File.Exists(certPath);\nif (!keyReady) throw new InvalidOperationException(\"No WeChat Pay public key or platform certificate configured.\");","typeGuard":null,"tryCatchPattern":"try { await apis.AddReceiverAsync(data); }\ncatch (TenpayApiRequestException ex) when (ex.Message.Contains(\"公钥或平台证书\"))\n{ await certificateManager.RefreshAsync(); await apis.AddReceiverAsync(data); }","preventionTips":["Configure the WeChat Pay public key (or deploy platform certificates) at startup and fail fast if absent","Refresh platform certificates after WeChat key rotation","Verify certificate files are readable by the application process in production","Monitor certificate/key expiry proactively"],"tags":["config","encryption","wechat-pay","profitsharing"],"backgroundTag":"missing-credentials","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}