main.tea 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import EasySDKKernel;
  2. type @kernel = EasySDKKernel
  3. init(kernel: EasySDKKernel) {
  4. @kernel = kernel;
  5. }
  6. model AlipayOfflineMaterialImageUploadResponse {
  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. imageId: string(name='image_id'),
  13. imageUrl: string(name='image_url')
  14. }
  15. api upload(imageName: string, imageFilePath: string): AlipayOfflineMaterialImageUploadResponse {
  16. var systemParams: map[string]string = {
  17. method = 'alipay.offline.material.image.upload',
  18. app_id = @kernel.getConfig("appId"),
  19. timestamp = @kernel.getTimestamp(),
  20. format = 'json',
  21. version = '1.0',
  22. alipay_sdk = @kernel.getSdkVersion(),
  23. charset = 'UTF-8',
  24. sign_type = @kernel.getConfig("signType"),
  25. app_cert_sn = @kernel.getMerchantCertSN(),
  26. alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
  27. };
  28. var bizParams: map[string]any = {
  29. };
  30. var textParams: map[string]string = {
  31. image_type = 'jpg',
  32. image_name = imageName
  33. };
  34. var fileParams: map[string]string = {
  35. image_content = imageFilePath
  36. };
  37. var boundary = @kernel.getRandomBoundary();
  38. __request.protocol = @kernel.getConfig("protocol");
  39. __request.method = 'POST';
  40. __request.pathname = '/gateway.do';
  41. __request.headers = {
  42. host = @kernel.getConfig("gatewayHost"),
  43. content-type = @kernel.concatStr('multipart/form-data;charset=utf-8;boundary=', boundary)
  44. };
  45. __request.query = @kernel.sortMap({
  46. sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig("merchantPrivateKey")),
  47. ... systemParams,
  48. });
  49. __request.body = @kernel.toMultipartRequestBody(textParams, fileParams, boundary);
  50. } returns {
  51. var respMap: map[string]any = @kernel.readAsJson(__response, "alipay.offline.material.image.upload");
  52. if (@kernel.isCertMode()) {
  53. if (@kernel.verify(respMap, @kernel.extractAlipayPublicKey(@kernel.getAlipayCertSN(respMap)))) {
  54. return @kernel.toRespModel(respMap);
  55. }
  56. } else {
  57. if (@kernel.verify(respMap, @kernel.getConfig("alipayPublicKey"))) {
  58. return @kernel.toRespModel(respMap);
  59. }
  60. }
  61. throw {
  62. message = '验签失败,请检查支付宝公钥设置是否正确。'
  63. }
  64. } runtime {
  65. ignoreSSL = @kernel.getConfig("ignoreSSL"),
  66. httpProxy = @kernel.getConfig("httpProxy"),
  67. connectTimeout = 100000,
  68. readTimeout = 100000,
  69. retry = {
  70. maxAttempts = 0
  71. }
  72. }