main.tea 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import EasySDKKernel;
  2. type @kernel = EasySDKKernel
  3. init(kernel: EasySDKKernel) {
  4. @kernel = kernel;
  5. }
  6. model AlipayOpenAppMiniTemplatemessageSendResponse {
  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. }
  13. api send(toUserId: string, formId: string, userTemplateId: string, page: string, data: string): AlipayOpenAppMiniTemplatemessageSendResponse {
  14. var systemParams: map[string]string = {
  15. method = 'alipay.open.app.mini.templatemessage.send',
  16. app_id = @kernel.getConfig("appId"),
  17. timestamp = @kernel.getTimestamp(),
  18. format = 'json',
  19. version = '1.0',
  20. alipay_sdk = @kernel.getSdkVersion(),
  21. charset = 'UTF-8',
  22. sign_type = @kernel.getConfig("signType"),
  23. app_cert_sn = @kernel.getMerchantCertSN(),
  24. alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
  25. };
  26. var bizParams: map[string]any = {
  27. to_user_id = toUserId,
  28. form_id = formId,
  29. user_template_id = userTemplateId,
  30. page = page,
  31. data = data
  32. };
  33. var textParams: map[string]string = {
  34. };
  35. __request.protocol = @kernel.getConfig("protocol");
  36. __request.method = 'POST';
  37. __request.pathname = '/gateway.do';
  38. __request.headers = {
  39. host = @kernel.getConfig("gatewayHost"),
  40. content-type = 'application/x-www-form-urlencoded;charset=utf-8'
  41. };
  42. __request.query = @kernel.sortMap({
  43. sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig("merchantPrivateKey")),
  44. ... systemParams,
  45. ... textParams
  46. });
  47. __request.body = @kernel.toUrlEncodedRequestBody(bizParams);
  48. } returns {
  49. var respMap: map[string]any = @kernel.readAsJson(__response, "alipay.open.app.mini.templatemessage.send");
  50. if (@kernel.isCertMode()) {
  51. if (@kernel.verify(respMap, @kernel.extractAlipayPublicKey(@kernel.getAlipayCertSN(respMap)))) {
  52. return @kernel.toRespModel(respMap);
  53. }
  54. } else {
  55. if (@kernel.verify(respMap, @kernel.getConfig("alipayPublicKey"))) {
  56. return @kernel.toRespModel(respMap);
  57. }
  58. }
  59. throw {
  60. message = '验签失败,请检查支付宝公钥设置是否正确。'
  61. }
  62. } runtime {
  63. ignoreSSL = @kernel.getConfig("ignoreSSL"),
  64. httpProxy = @kernel.getConfig("httpProxy"),
  65. connectTimeout = 15000,
  66. readTimeout = 15000,
  67. retry = {
  68. maxAttempts = 0
  69. }
  70. }