### Create Alipay Mobile Website Payment (Wap Pay) in Go Source: https://github.com/smartwalle/alipay/blob/master/README.md This Go code example illustrates the process of initiating an Alipay mobile website payment. It covers essential steps such as client initialization with application ID and private key, loading various necessary certificates (application public key, Alipay root certificate, and Alipay public key certificate), and optionally setting an encryption key. The snippet then configures the payment request with details like notification URL, return URL, subject, unique order number, total amount, and product code, finally generating the payment URL for redirection. ```go var privateKey = "xxx" // 必须,上一步中使用 RSA签名验签工具 生成的私钥 var client, err = alipay.New(appId, privateKey, false) if err != nil { fmt.Println(err) return } // 加载应用公钥证书 if err = client.LoadAppCertPublicKeyFromFile("appCertPublicKey_2017011104995404.crt"); err != nil { // 错误处理 } // 加载支付宝根证书 if err = client.LoadAliPayRootCertFromFile("alipayRootCert.crt"); err != nil { // 错误处理 } // 加载支付宝公钥证书 if err = client.LoadAlipayCertPublicKeyFromFile("alipayCertPublicKey_RSA2.crt"); err != nil { // 错误处理 } // 加载内容密钥,可选 if err = client.SetEncryptKey("FtVd5SgrsUzYQRAPBmejHQ=="); err != nil { // 错误处理 } var p = alipay.TradeWapPay{} p.NotifyURL = "http://xxx" p.ReturnURL = "http://xxx" p.Subject = "标题" p.OutTradeNo = "传递一个唯一单号" p.TotalAmount = "10.00" p.ProductCode = "QUICK_WAP_WAY" var url, err = client.TradeWapPay(p) if err != nil { fmt.Println(err) } // 这个 payURL 即是用于打开支付宝支付页面的 URL,可将输出的内容复制,到浏览器中访问该 URL 即可打开支付页面。 var payURL = url.String() fmt.Println(payURL) ``` -------------------------------- ### Go: Implementing Alipay File Upload Source: https://github.com/smartwalle/alipay/blob/master/README.md Illustrates how to use the custom request mechanism to implement the `alipay.open.file.upload` interface. It highlights the necessity of setting `p.Encrypt = false` for file uploads and provides examples for adding file content using either a file path or an `io.Reader`. ```Go var p = alipay.NewPayload("alipay.open.file.upload") p.Encrypt = false // 文件上传不支持接口内容加密 // 设置参数 p.AddParam("biz_code", "content_creation") // 添加文件 p.AddFilePath("file_content", "a.jpg", "path/a.jpg") // 或者 p.AddFileObject("file_content", "a.jpg", io.Reader) var result map[string]interface{} var err = client.Request(p, &result) ``` -------------------------------- ### Go: Customizing Alipay Requests with Payload Source: https://github.com/smartwalle/alipay/blob/master/README.md Demonstrates how to use `alipay.Payload` and `alipay.Client.Request()` to interact with Alipay interfaces not explicitly implemented in the SDK. It covers adding common and business parameters, and shows scenarios for initiating network requests, generating URLs, and signing parameters. ```Go var p = alipay.NewPayload("这里是接口名称,如:alipay.trade.query") // 添加公共请求参数,如:app_auth_token p.AddParam("key", "value") // 添加请求参数(业务相关) p.AddBizField("key", "value") // 应用场景一:需要向支付宝服务器发起网络请求,如交易查询接口(alipay.trade.query) var result map[string]interface{} // result 也可以为结构体,可参照 alipay.TradeQueryRsp var err = client.Request(p, &result) if err != nil { ... } // 应用场景二:只需要生成 URL,如网页支付(alipay.trade.page.pay) var url, err = clietn.BuildURL(p) ... // 应用场景三:只需要对参数进行签名,如 App 支付(alipay.trade.app.pay) var s, err = client.EncodeParam(p) ... ``` -------------------------------- ### Go: Configuring OpenTelemetry Tracing for Alipay Client Source: https://github.com/smartwalle/alipay/blob/master/README.md Shows how to integrate OpenTelemetry for distributed tracing with the `smartwalle/alipay` client. It demonstrates configuring a custom `http.Client` with `otelhttp.NewTransport` to capture HTTP request spans, and then initializing the Alipay client with this instrumented HTTP client. ```Go // HTTP客户端 httpClient := &http.Client{ Timeout: 30 * time.Second, Transport: otelhttp.NewTransport( http.DefaultTransport, otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string { return r.Method + " " + r.URL.Path }), ), } // 初始化支付宝客户端 client, err := alipay.New(appId, privateKey, false, alipay.WithHTTPClient(httpClient)) if err != nil { fmt.Println(err) } ``` -------------------------------- ### Alipay Implemented API Interfaces and Client Methods Source: https://github.com/smartwalle/alipay/blob/master/README.md Lists the Alipay API interfaces that have been implemented in the SDK, along with their corresponding method names in the client structure. The name after the hyphen (-) indicates the method name within the Client struct. ```APIDOC alipay.trade.wap.pay - TradeWapPay() alipay.trade.page.pay - TradePagePay() alipay.trade.query - TradeQuery() alipay.trade.pay - TradePay() alipay.trade.create - TradeCreate() alipay.trade.precreate - TradePreCreate() alipay.trade.cancel - TradeCancel() alipay.trade.close - TradeClose() alipay.trade.refund - TradeRefund() alipay.trade.app.pay - TradeAppPay() alipay.trade.fastpay.refund.query - TradeFastpayRefundQuery() alipay.trade.orderinfo.sync - TradeOrderInfoSync() alipay.fund.trans.toaccount.transfer - FundTransToAccountTransfer() alipay.fund.trans.order.query - FundTransOrderQuery() alipay.fund.auth.order.voucher.create - FundAuthOrderVoucherCreate() alipay.fund.auth.operation.detail.query - FundAuthOperationDetailQuery() alipay.fund.auth.operation.cancel - FundAuthOperationCancel() alipay.fund.auth.order.unfreeze - FundAuthOrderUnfreeze() alipay.fund.auth.order.freeze - FundAuthOrderFreeze() alipay.fund.auth.order.app.freeze - FundAuthOrderAppFreeze() alipay.data.dataservice.bill.downloadurl.query - BillDownloadURLQuery() alipay.data.bill.balance.query - BillBalanceQuery() alipay.user.certify.open.initialize - UserCertifyOpenInitialize() alipay.user.certify.open.certify - UserCertifyOpenCertify() alipay.user.certify.open.query - UserCertifyOpenQuery() PublicAppAuthorize() alipay.system.oauth.token - SystemOauthToken() alipay.user.info.share - UserInfoShare() com.alipay.account.auth - AccountAuth() alipay.user.agreement.page.sign - AgreementPageSign() alipay.user.agreement.query - AgreementQuery() alipay.user.agreement.unsign - AgreementUnsign() alipay.fund.trans.uni.transfer - FundTransUniTransfer() alipay.fund.trans.common.query - FundTransCommonQuery() alipay.fund.account.query - FundAccountQuery() my.getPhoneNumber - DecodePhoneNumber() ``` -------------------------------- ### Initialize Alipay Client with Old Sandbox Gateway in Go Source: https://github.com/smartwalle/alipay/blob/master/README.md This Go snippet demonstrates how to initialize the Alipay SDK client to use the old sandbox gateway address. By default, the SDK uses the new sandbox gateway, but `alipay.WithPastSandboxGateway()` can be used to specify the older endpoint. ```go alipay.New(appId, privateKey, isProduction, alipay.WithPastSandboxGateway()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.