12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import EasySDKKernel;
- type @kernel = EasySDKKernel
- init(kernel: EasySDKKernel) {
- @kernel = kernel;
- }
- model HuabeiConfig {
- hbFqNum: string(name='hb_fq_num'),
- hbFqSellerPercent: string(name='hb_fq_seller_percent')
- }
- model AlipayTradeCreateResponse {
- httpBody: string(name='http_body', description='响应原始字符串'),
- code: string(name='code'),
- msg: string(name='msg'),
- subCode: string(name='sub_code'),
- subMsg: string(name='sub_msg'),
- outTradeNo: string(name='out_trade_no'),
- tradeNo: string(name='trade_no')
- }
- api create(subject: string, outTradeNo: string, totalAmount: string, buyerId: string, extendParams: HuabeiConfig): AlipayTradeCreateResponse {
- var systemParams: map[string]string = {
- method = 'alipay.trade.create',
- app_id = @kernel.getConfig("appId"),
- timestamp = @kernel.getTimestamp(),
- format = 'json',
- version = '1.0',
- alipay_sdk = @kernel.getSdkVersion(),
- charset = 'UTF-8',
- sign_type = @kernel.getConfig("signType"),
- app_cert_sn = @kernel.getMerchantCertSN(),
- alipay_root_cert_sn = @kernel.getAlipayRootCertSN()
- };
- var bizParams: map[string]any = {
- subject = subject,
- out_trade_no = outTradeNo,
- total_amount = totalAmount,
- buyer_id = buyerId,
- extend_params = extendParams
- };
- var textParams: map[string]string = {
- };
- __request.protocol = @kernel.getConfig("protocol");
- __request.method = 'POST';
- __request.pathname = '/gateway.do';
- __request.headers = {
- host = @kernel.getConfig("gatewayHost"),
- content-type = 'application/x-www-form-urlencoded;charset=utf-8'
- };
- __request.query = @kernel.sortMap({
- sign = @kernel.sign(systemParams, bizParams, textParams, @kernel.getConfig("merchantPrivateKey")),
- ... systemParams,
- ... textParams
- });
- __request.body = @kernel.toUrlEncodedRequestBody(bizParams);
- } returns {
- var respMap: map[string]any = @kernel.readAsJson(__response, "alipay.trade.create");
- if (@kernel.isCertMode()) {
- if (@kernel.verify(respMap, @kernel.extractAlipayPublicKey(@kernel.getAlipayCertSN(respMap)))) {
- return @kernel.toRespModel(respMap);
- }
- } else {
- if (@kernel.verify(respMap, @kernel.getConfig("alipayPublicKey"))) {
- return @kernel.toRespModel(respMap);
- }
- }
-
- throw {
- message = '验签失败,请检查支付宝公钥设置是否正确。'
- }
-
- } runtime {
- ignoreSSL = @kernel.getConfig("ignoreSSL"),
- httpProxy = @kernel.getConfig("httpProxy"),
- connectTimeout = 15000,
- readTimeout = 15000,
- retry = {
- maxAttempts = 0
- }
- }
|