main.tea 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import EasySDKKernel;
  2. type @kernel = EasySDKKernel
  3. init(kernel: EasySDKKernel) {
  4. @kernel = kernel;
  5. }
  6. model IdentityParam {
  7. identityType: string(name='identity_type'),
  8. certType: string(name='cert_type'),
  9. certName: string(name='cert_name'),
  10. certNo: string(name='cert_no')
  11. }
  12. model MerchantConfig {
  13. returnUrl: string(name='return_url')
  14. }
  15. model AlipayUserCertifyOpenInitializeResponse {
  16. httpBody: string(name='http_body', description='响应原始字符串'),
  17. code: string(name='code'),
  18. msg: string(name='msg'),
  19. subCode: string(name='sub_code'),
  20. subMsg: string(name='sub_msg'),
  21. certifyId: string(name='certify_id')
  22. }
  23. model AlipayUserCertifyOpenCertifyResponse {
  24. body: string(name='body', description='认证服务请求地址')
  25. }
  26. model AlipayUserCertifyOpenQueryResponse {
  27. httpBody: string(name='http_body', description='响应原始字符串'),
  28. code: string(name='code'),
  29. msg: string(name='msg'),
  30. subCode: string(name='sub_code'),
  31. subMsg: string(name='sub_msg'),
  32. passed: string(name='passed'),
  33. identityInfo: string(name='identity_info'),
  34. materialInfo: string(name='material_info')
  35. }
  36. api init(outerOrderNo: string, bizCode: string, identityParam: IdentityParam, merchantConfig: MerchantConfig): AlipayUserCertifyOpenInitializeResponse {
  37. var systemParams: map[string]string = {
  38. method = 'alipay.user.certify.open.initialize',
  39. app_id = @kernel.getConfig("appId"),
  40. timestamp = @kernel.getTimestamp(),
  41. format = 'json',
  42. version = '1.0',
  43. alipay_sdk = @kernel.getSdkVersion(),
  44. charset = 'UTF-8',
  45. sign_type = @kernel.getConfig("signType"),
  46. app_cert_sn = @kernel.getMerchantCertSN(),
  47. alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
  48. };
  49. var bizParams: map[string]any = {
  50. outer_order_no = outerOrderNo,
  51. biz_code = bizCode,
  52. identity_param = identityParam,
  53. merchant_config = merchantConfig
  54. };
  55. var textParams: map[string]string = {
  56. };
  57. __request.protocol = @kernel.getConfig("protocol");
  58. __request.method = 'POST';
  59. __request.pathname = '/gateway.do';
  60. __request.headers = {
  61. host = @kernel.getConfig("gatewayHost"),
  62. content-type = 'application/x-www-form-urlencoded;charset=utf-8'
  63. };
  64. __request.query = @kernel.sortMap({
  65. sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig("merchantPrivateKey")),
  66. ... systemParams,
  67. ... textParams
  68. });
  69. __request.body = @kernel.toUrlEncodedRequestBody(bizParams);
  70. } returns {
  71. var respMap: map[string]any = @kernel.readAsJson(__response, "alipay.user.certify.open.initialize");
  72. if (@kernel.isCertMode()) {
  73. if (@kernel.verify(respMap, @kernel.extractAlipayPublicKey(@kernel.getAlipayCertSN(respMap)))) {
  74. return @kernel.toRespModel(respMap);
  75. }
  76. } else {
  77. if (@kernel.verify(respMap, @kernel.getConfig("alipayPublicKey"))) {
  78. return @kernel.toRespModel(respMap);
  79. }
  80. }
  81. throw {
  82. message = '验签失败,请检查支付宝公钥设置是否正确。'
  83. }
  84. } runtime {
  85. ignoreSSL = @kernel.getConfig("ignoreSSL"),
  86. httpProxy = @kernel.getConfig("httpProxy"),
  87. connectTimeout = 15000,
  88. readTimeout = 15000,
  89. retry = {
  90. maxAttempts = 0
  91. }
  92. }
  93. function certify(certifyId: string): AlipayUserCertifyOpenCertifyResponse {
  94. var systemParams: map[string]string = {
  95. method = 'alipay.user.certify.open.certify',
  96. app_id = @kernel.getConfig("appId"),
  97. timestamp = @kernel.getTimestamp(),
  98. format = 'json',
  99. version = '1.0',
  100. alipay_sdk = @kernel.getSdkVersion(),
  101. charset = 'UTF-8',
  102. sign_type = @kernel.getConfig("signType"),
  103. app_cert_sn = @kernel.getMerchantCertSN(),
  104. alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
  105. };
  106. var bizParams: map[string]any = {
  107. certify_id = certifyId
  108. };
  109. var textParams: map[string]string = {
  110. };
  111. var sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig('merchantPrivateKey'));
  112. var response: map[string]string = {
  113. body = @kernel.generatePage('GET', systemParams, bizParams, textParams, sign)
  114. };
  115. return response;
  116. }
  117. api query(certifyId: string): AlipayUserCertifyOpenQueryResponse {
  118. var systemParams: map[string]string = {
  119. method = 'alipay.user.certify.open.query',
  120. app_id = @kernel.getConfig("appId"),
  121. timestamp = @kernel.getTimestamp(),
  122. format = 'json',
  123. version = '1.0',
  124. alipay_sdk = @kernel.getSdkVersion(),
  125. charset = 'UTF-8',
  126. sign_type = @kernel.getConfig("signType"),
  127. app_cert_sn = @kernel.getMerchantCertSN(),
  128. alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
  129. };
  130. var bizParams: map[string]any = {
  131. certify_id = certifyId
  132. };
  133. var textParams: map[string]string = {
  134. };
  135. __request.protocol = @kernel.getConfig("protocol");
  136. __request.method = 'POST';
  137. __request.pathname = '/gateway.do';
  138. __request.headers = {
  139. host = @kernel.getConfig("gatewayHost"),
  140. content-type = 'application/x-www-form-urlencoded;charset=utf-8'
  141. };
  142. __request.query = @kernel.sortMap({
  143. sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig("merchantPrivateKey")),
  144. ... systemParams,
  145. ... textParams
  146. });
  147. __request.body = @kernel.toUrlEncodedRequestBody(bizParams);
  148. } returns {
  149. var respMap: map[string]any = @kernel.readAsJson(__response, "alipay.user.certify.open.query");
  150. if (@kernel.isCertMode()) {
  151. if (@kernel.verify(respMap, @kernel.extractAlipayPublicKey(@kernel.getAlipayCertSN(respMap)))) {
  152. return @kernel.toRespModel(respMap);
  153. }
  154. } else {
  155. if (@kernel.verify(respMap, @kernel.getConfig("alipayPublicKey"))) {
  156. return @kernel.toRespModel(respMap);
  157. }
  158. }
  159. throw {
  160. message = '验签失败,请检查支付宝公钥设置是否正确。'
  161. }
  162. } runtime {
  163. ignoreSSL = @kernel.getConfig("ignoreSSL"),
  164. httpProxy = @kernel.getConfig("httpProxy"),
  165. connectTimeout = 15000,
  166. readTimeout = 15000,
  167. retry = {
  168. maxAttempts = 0
  169. }
  170. }