main.tea 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import EasySDKKernel;
  2. type @kernel = EasySDKKernel
  3. init(kernel: EasySDKKernel) {
  4. @kernel = kernel;
  5. }
  6. model AlipaySecurityRiskContentDetectResponse {
  7. httpBody: string(name='http_body', description='响应原始字符串'),
  8. code: string(name='code'),
  9. msg: string(name='msg'),
  10. subCode: string(name='sub_code'),
  11. subMsg: string(name='sub_msg'),
  12. action: string(name='action'),
  13. keywords: [ string ](name='keywords'),
  14. uniqueId: string(name='unique_id')
  15. }
  16. api detect(content: string): AlipaySecurityRiskContentDetectResponse {
  17. var systemParams: map[string]string = {
  18. method = 'alipay.security.risk.content.detect',
  19. app_id = @kernel.getConfig("appId"),
  20. timestamp = @kernel.getTimestamp(),
  21. format = 'json',
  22. version = '1.0',
  23. alipay_sdk = @kernel.getSdkVersion(),
  24. charset = 'UTF-8',
  25. sign_type = @kernel.getConfig("signType"),
  26. app_cert_sn = @kernel.getMerchantCertSN(),
  27. alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
  28. };
  29. var bizParams: map[string]any = {
  30. content = content
  31. };
  32. var textParams: map[string]string = {
  33. };
  34. __request.protocol = @kernel.getConfig("protocol");
  35. __request.method = 'POST';
  36. __request.pathname = '/gateway.do';
  37. __request.headers = {
  38. host = @kernel.getConfig("gatewayHost"),
  39. content-type = 'application/x-www-form-urlencoded;charset=utf-8'
  40. };
  41. __request.query = @kernel.sortMap({
  42. sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig("merchantPrivateKey")),
  43. ... systemParams,
  44. ... textParams
  45. });
  46. __request.body = @kernel.toUrlEncodedRequestBody(bizParams);
  47. } returns {
  48. var respMap: map[string]any = @kernel.readAsJson(__response, "alipay.security.risk.content.detect");
  49. if (@kernel.isCertMode()) {
  50. if (@kernel.verify(respMap, @kernel.extractAlipayPublicKey(@kernel.getAlipayCertSN(respMap)))) {
  51. return @kernel.toRespModel(respMap);
  52. }
  53. } else {
  54. if (@kernel.verify(respMap, @kernel.getConfig("alipayPublicKey"))) {
  55. return @kernel.toRespModel(respMap);
  56. }
  57. }
  58. throw {
  59. message = '验签失败,请检查支付宝公钥设置是否正确。'
  60. }
  61. } runtime {
  62. ignoreSSL = @kernel.getConfig("ignoreSSL"),
  63. httpProxy = @kernel.getConfig("httpProxy"),
  64. connectTimeout = 15000,
  65. readTimeout = 15000,
  66. retry = {
  67. maxAttempts = 0
  68. }
  69. }