### Node.js Alipay Native Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt This example demonstrates how to initiate an Alipay native payment (QR code) using the SDK. Remember to install the SDK and replace placeholder values for merchant ID and API key. ```javascript // 支付宝扫码支付示例 async function aliNativePay() { const AliPay = YunGouOS.AliPay; const params = { out_trade_no: 'ORDER_' + Date.now(), total_fee: '0.01', mch_id: 'YOUR_ALIPAY_MCH_ID', body: '测试商品', type: '2', notify_url: 'https://your-domain.com/pay/notify', key: 'YOUR_ALIPAY_KEY' }; try { const result = await AliPay.nativePay(params); console.log('支付宝二维码:', result); } catch (error) { console.error('支付失败:', error.message); } } ``` -------------------------------- ### Install yungouos-pay-node-sdk via NPM Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Install the SDK using npm. This is the recommended installation method for Node.js projects. ```sh npm i yungouos-pay-node-sdk ``` -------------------------------- ### Install YunGouOS-PAY-SDK via NPM Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JS-SDK/README.md Install the SDK using npm. This is the recommended method for project integration. ```sh npm i yungouos-pay-sdk ``` -------------------------------- ### Install Yungouos-pay-uniapp-sdk via NPM Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Install the SDK using NPM. This is the recommended method for integrating the SDK into your Uniapp project. ```sh npm i yungouos-pay-uniapp-sdk ``` -------------------------------- ### Spring Boot Integration Example Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/README.md Example demonstrating integration with WeChat, Alipay, and callback methods in a Spring Boot application. This is useful for backend development requiring payment processing. ```Java This is a placeholder for actual code. Please refer to the provided Gitee link for the complete example. ``` -------------------------------- ### Node.js WeChat Native Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Use this snippet to initiate a WeChat native payment (QR code). Ensure you have installed the 'yungouos-pay-node-sdk' package. Replace placeholders like 'YOUR_MCH_ID' and 'YOUR_PAY_KEY' with your actual credentials. ```javascript // 安装依赖 // npm install yungouos-pay-node-sdk const YunGouOS = require('yungouos-pay-node-sdk'); // 微信扫码支付示例 async function wxNativePay() { const WxPay = YunGouOS.WxPay; const params = { out_trade_no: 'ORDER_' + Date.now(), total_fee: '0.01', mch_id: 'YOUR_MCH_ID', body: '测试商品', type: '2', // 返回二维码图片地址 notify_url: 'https://your-domain.com/pay/notify', key: 'YOUR_PAY_KEY' }; try { const result = await WxPay.nativePay(params); console.log('支付二维码:', result); } catch (error) { console.error('支付失败:', error.message); } } ``` -------------------------------- ### Alipay PC Website Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Enables Alipay payments for PC websites, redirecting users to the Alipay payment gateway. The `result.getForm()` should be outputted to the page to automatically redirect the user to the Alipay checkout. ```java import com.yungouos.pay.alipay.AliPay; import com.yungouos.pay.entity.AliPayWebPayBiz; // 电脑网站支付示例 String out_trade_no = "ORDER_" + System.currentTimeMillis(); String total_fee = "0.01"; String mch_id = "YOUR_ALIPAY_MCH_ID"; String body = "电脑网站支付-测试商品"; String app_id = null; String attach = "附加数据"; String notify_url = "https://your-domain.com/pay/notify"; String return_url = "https://your-domain.com/pay/return"; String config_no = null; String auto = "0"; String auto_node = null; HbFqBiz hbFqBiz = null; BizParams bizParams = null; String key = "YOUR_ALIPAY_KEY"; try { AliPayWebPayBiz result = AliPay.webPay(out_trade_no, total_fee, mch_id, body, app_id, attach, notify_url, return_url, config_no, auto, auto_node, hbFqBiz, bizParams, key); System.out.println("支付表单:" + result.getForm()); // 将form表单输出到页面,自动跳转支付宝收银台 } catch (PayException e) { System.out.println("支付失败:" + e.getMessage()); } ``` -------------------------------- ### Alipay Scan to Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Generates a QR code for Alipay payment. The `type` parameter determines the output: '1' for a native payment link, '2' for a QR code image URL. This is suitable for scenarios where users scan a QR code to pay. ```java import com.yungouos.pay.alipay.AliPay; // 支付宝扫码支付示例 String out_trade_no = "ORDER_" + System.currentTimeMillis(); String total_fee = "0.01"; String mch_id = "YOUR_ALIPAY_MCH_ID"; // 支付宝商户号 String body = "支付宝支付-测试商品"; String type = "2"; // 1-返回原生支付链接,2-返回二维码图片地址 String app_id = null; String attach = "附加数据"; String notify_url = "https://your-domain.com/pay/notify"; String config_no = null; String auto = "0"; String auto_node = null; HbFqBiz hbFqBiz = null; // 花呗分期参数 BizParams bizParams = null; String key = "YOUR_ALIPAY_KEY"; try { String qrCodeUrl = AliPay.nativePay(out_trade_no, total_fee, mch_id, body, type, app_id, attach, notify_url, config_no, auto, auto_node, hbFqBiz, bizParams, key); System.out.println("支付宝二维码地址:" + qrCodeUrl); } catch (PayException e) { System.out.println("支付失败:" + e.getMessage()); } ``` -------------------------------- ### WeChat APP Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Initiates a WeChat APP payment. Requires an APPID registered on the WeChat Open Platform. The returned parameters should be used with the WeChat SDK on the APP side to launch the payment. ```java import com.yungouos.pay.wxpay.WxPay; import com.alibaba.fastjson.JSONObject; // APP支付示例 String app_id = "OPEN_APP_ID"; // 微信开放平台申请的APPID String out_trade_no = "ORDER_" + System.currentTimeMillis(); String total_fee = "0.01"; String mch_id = "YOUR_MCH_ID"; String body = "APP支付-测试商品"; String attach = "附加数据"; String notify_url = "https://your-domain.com/pay/notify"; String config_no = null; String auto = "0"; String auto_node = null; BizParams bizParams = null; String key = "YOUR_PAY_KEY"; try { JSONObject appParams = WxPay.appPay(app_id, out_trade_no, total_fee, mch_id, body, attach, notify_url, config_no, auto, auto_node, bizParams, key); System.out.println("APP支付参数:" + appParams.toJSONString()); // 将appParams返回给APP端,调用微信SDK发起支付 } catch (PayException e) { System.out.println("支付失败:" + e.getMessage()); } ``` -------------------------------- ### Initiate Alipay Refund Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Starts a refund process for an Alipay transaction. Requires order details, merchant ID, refund amount, custom refund ID, description, and callback URL. ```java AliPay.orderRefund(订单号, 支付宝商户号, 退款金额,自定义退款单号,退款描述,回调地址,商户密钥); ``` -------------------------------- ### Alipay WAP Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Facilitates Alipay mobile web payments, redirecting users to the Alipay app via their mobile browser. This is for payments initiated on mobile websites. ```java import com.yungouos.pay.alipay.AliPay; // 支付宝WAP支付示例 String out_trade_no = "ORDER_" + System.currentTimeMillis(); String total_fee = "0.01"; String mch_id = "YOUR_ALIPAY_MCH_ID"; String body = "WAP支付-测试商品"; String app_id = null; String attach = "附加数据"; String notify_url = "https://your-domain.com/pay/notify"; String config_no = null; String auto = "0"; String auto_node = null; HbFqBiz hbFqBiz = null; BizParams bizParams = null; String key = "YOUR_ALIPAY_KEY"; try { String wapUrl = AliPay.wapPay(out_trade_no, total_fee, mch_id, body, app_id, attach, notify_url, config_no, auto, auto_node, hbFqBiz, bizParams, key); System.out.println("WAP支付链接:" + wapUrl); // 重定向到wapUrl即可打开支付宝支付 } catch (PayException e) { System.out.println("支付失败:" + e.getMessage()); } ``` -------------------------------- ### Java Spring Boot Payment Callback Handling Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt This Java example shows how to handle asynchronous payment notifications in a Spring Boot application. It includes parsing callback parameters and verifying the signature using 'PaySignUtil'. Return 'SUCCESS' to acknowledge receipt, otherwise 'FAIL'. ```java import com.yungouos.pay.util.PaySignUtil; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.Map; // Spring Boot 回调处理示例 @RestController public class PayNotifyController { @PostMapping("/pay/notify") public String payNotify(HttpServletRequest request) { // 获取回调参数 String code = request.getParameter("code"); // 1-支付成功 String orderNo = request.getParameter("orderNo"); // 系统订单号 String outTradeNo = request.getParameter("outTradeNo"); // 商户订单号 String payNo = request.getParameter("payNo"); // 微信/支付宝流水号 String money = request.getParameter("money"); // 支付金额 String mchId = request.getParameter("mchId"); // 商户号 String payChannel = request.getParameter("payChannel"); // 支付渠道 String time = request.getParameter("time"); // 支付时间 String attach = request.getParameter("attach"); // 附加数据 String openId = request.getParameter("openId"); // 用户openId String sign = request.getParameter("sign"); // 签名 // 验证签名 Map params = new HashMap<>(); params.put("code", code); params.put("orderNo", orderNo); params.put("outTradeNo", outTradeNo); params.put("payNo", payNo); params.put("money", money); params.put("mchId", mchId); String key = "YOUR_PAY_KEY"; String checkSign = PaySignUtil.createSign(params, key); if (!checkSign.equals(sign)) { return "FAIL"; // 签名验证失败 } if ("1".equals(code)) { // 支付成功,处理业务逻辑 // 1. 验证订单金额 // 2. 更新订单状态 // 3. 发货等业务操作 System.out.println("订单支付成功:" + outTradeNo); } return "SUCCESS"; // 返回SUCCESS表示已接收 } } ``` -------------------------------- ### Initialize Alipay Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-PHP-SDK/README.md Instantiate the AliPay object for Alipay payments. Ensure the AliPay.php file is imported. ```php $alipay= new AliPay(); ``` -------------------------------- ### QQ Mini Program Pay (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Initiates a QQ Mini Program payment. Handles the response and constructs the payment parameters for the QQ payment interface. ```APIDOC ## QQ Mini Program Pay (Asynchronous) ### Description Initiates a QQ Mini Program payment. Handles the response and constructs the payment parameters for the QQ payment interface. ### Method `WxPay.qqPay` ### Parameters - **app_id** (string) - Required - The application ID. - **access_token** (string) - Required - The access token. - **out_trade_no** (string) - Required - The unique order number. - **total_fee** (number) - Required - The total payment amount. - **mch_id** (string) - Required - The merchant ID. - **body** (string) - Required - The description of the goods. - **attach** (string) - Optional - User-defined data. - **notify_url** (string) - Required - The URL for receiving payment notifications. - **return_url** (string) - Optional - The URL to redirect to after payment. - **auto** (boolean) - Optional - Whether to automatically process. - **auto_node** (string) - Optional - Automatic processing node. - **config_no** (string) - Optional - Configuration number. - **biz_params** (object) - Optional - Business-specific parameters. - **payKey** (string) - Required - The payment key. ### Response Example ```json { "code": 0, "data": { "minPayParam": { "appId": "wx1234567890abcdef", "timeStamp": "1678886400", "nonceStr": "random_string", "package": "prepay_id=wx20230315100000abcdef1234567890", "signType": "MD5", "paySign": "a1b2c3d4e5f67890abcdef1234567890" } } } ``` ### Success Response (200) - **code** (number) - Indicates the result of the operation (0 for success). - **data** (object) - Contains payment parameters if successful. - **minPayParam** (object) - Parameters required for initiating the QQ payment. ### Error Handling - If `code` is not 0 or `data` is null, the payment failed. - If `minPayParam` is null or empty, the payment failed. ``` -------------------------------- ### QQ Mini Program Payment (Async) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Initiates a QQ Mini Program payment asynchronously. Handles success and failure callbacks for the payment interface. ```javascript WxPay.qqPay(app_id,access_token,out_trade_no, total_fee, mch_id, body, attach, notify_url, return_url, auto, auto_node, config_no, biz_params,payKey).then((response)=>{ //接口返回结果 if(response.code!=0||response.data==null){ console.log("支付失败"); return; } let result=response.data; let minPayParam=result.minPayParam; if(minPayParam==null||minPayParam==''||minPayParam==undefined){ console.log("支付失败"); return; } //构建支付成功方法 minPayParam.success = (response) => { if (response.errMsg == 'requestWxPayment:ok') { //支付成功 console.log("小程序支付成功"); } } //构建支付失败方法 minPayParam.fail = (response) => { if (response.errMsg == 'requestWxPayment:fail cancel') { //取消支付 console.log("取消支付"); } } //拉起小程序支付界面 qq.requestWxPayment(minPayParam); }); ``` -------------------------------- ### WeChat - Get OAuth URL Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Generates a URL for WeChat authorization. ```APIDOC ## 获取微信授权URL ### Description Generates a URL for WeChat authorization. ### Method GET (Implied by SDK method call) ### Endpoint Not specified, SDK handles the integration. ### Parameters - **merchantId** (string) - Required - The merchant ID. - **redirectUri** (string) - Required - The URI to redirect to after authorization. - **responseType** (string) - Required - The type of response (e.g., 'code'). - **extraParamsJson** (string) - Optional - Additional parameters in JSON string format. - **merchantKey** (string) - Required - The merchant's secret key. ### Response #### Success Response (200) - **oauthUrl** (string) - The generated WeChat OAuth URL. ``` -------------------------------- ### Get Authorization URL (Async) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Asynchronously obtains a WeChat authorization URL. Requires merchant ID, callback URL, and optional parameters. ```javascript WxLogin.getOauthUrl(mch_id, callback_url, type, params, key).then((response)=>{ //接口返回结果 console.log(response); }); ``` -------------------------------- ### Alipay Initialization Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Imports the Alipay object from the Yungouos Pay SDK. ```APIDOC ## Alipay Initialization ### Description Imports the Alipay object from the Yungouos Pay SDK. ### Code ```javascript import { AliPay } from 'yungouos-pay-node-sdk' ``` ``` -------------------------------- ### Get Authorization URL (Sync) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Synchronously obtains a WeChat authorization URL. Requires merchant ID, callback URL, and optional parameters. ```javascript let result =await WxLogin.getOauthUrlAsync(mch_id, callback_url, type, params, key); //获取授权链接结果 console.log(result); ``` -------------------------------- ### WeChat Mini Program Payment (Jump/Half-screen for Individuals) (Synchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Prepare parameters for initiating a WeChat Mini Program payment that jumps to or uses a half-screen interface, specifically for individual accounts. This method generates the `extraData` required for `wx.openEmbeddedMiniProgram`. ```js let params = WxPay.minAppPayParams(out_trade_no, total_fee, mch_id, body,app_id, attach, title, notify_url, auto, auto_node, config_no, biz_params, payKey); wx.openEmbeddedMiniProgram({ appId: 'wxd9634afb01b983c0',//支付收银小程序的appid 固定值 不可修改 path: '/pages/pay/pay',//支付页面 固定值 不可修改 extraData: params,//携带的参数 success(res) { console.log("小程序拉起成功"); }, fail(res) { } }); ``` -------------------------------- ### Get URL Parameters Utility Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-SpringBoot-Demo/src/main/resources/templates/login.html A helper function to extract query parameters from a given URL. It uses a regular expression to parse key-value pairs. ```javascript function getUrlParams(url) { const paramsRegex = /\[?&]?([^=&]+)=([^&]*)/gi; const params = {}; let match; while (match = paramsRegex.exec(url)) { params[match[1]] = match[2]; } return params; } ``` -------------------------------- ### Node.js Order Query Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Query the status and details of an order using its unique 'out_trade_no'. This function requires your merchant ID and API key for authentication. ```javascript // 订单查询示例 async function queryOrder() { const Order = YunGouOS.Order; try { const result = await Order.getOrderInfoByOutTradeNo({ out_trade_no: 'ORDER_123456789', mch_id: 'YOUR_MCH_ID', key: 'YOUR_PAY_KEY' }); console.log('订单状态:', result.status); console.log('支付金额:', result.money); } catch (error) { console.error('查询失败:', error.message); } } ``` -------------------------------- ### Initialize WeChat Pay Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-PHP-SDK/README.md Instantiate the WxPay object for WeChat payments. Ensure the WxPay.php file is imported. ```php $wxpay = new WxPay(); ``` -------------------------------- ### Get Authorization URL (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JS-SDK/README.md Obtains the WeChat authorization URL asynchronously. Requires merchant ID, callback URL, type, optional parameters, and API key. ```APIDOC ## Get Authorization URL (Asynchronous) ### Description Obtains the WeChat authorization URL asynchronously. ### Method GET (Implied by SDK function) ### Endpoint Not specified, SDK function call. ### Parameters - **mch_id** (string) - Required - Merchant ID. - **callback_url** (string) - Required - The URL to redirect to after authorization. - **type** (string) - Required - Type of login (e.g., 'snsapi_userinfo'). - **params** (object) - Optional - Additional parameters. - **key** (string) - Required - API key for authentication. ### Request Example ```javascript WxLogin.getOauthUrl(mch_id, callback_url, type, params, key).then((response) => { console.log(response); }); ``` ### Response #### Success Response (200) - **response** (object) - The authorization URL and related information. ``` -------------------------------- ### QQ Mini Program Pay (Personal) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Returns parameters for redirecting to the 'Pay Cashier' mini program for QQ mini program payments. This is specifically for personal accounts. ```java JSONObject qqPayParams = WxPay.qqPayParams(System.currentTimeMillis() + "", "0.01", mchId, "QQ小程序支付测试", null,null, null, null, null, null, null, null, null, key); ``` -------------------------------- ### Get Authorization URL (Synchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JS-SDK/README.md Obtains the WeChat authorization URL synchronously. Requires merchant ID, callback URL, type, optional parameters, and API key. ```APIDOC ## Get Authorization URL (Synchronous) ### Description Obtains the WeChat authorization URL synchronously. ### Method GET (Implied by SDK function) ### Endpoint Not specified, SDK function call. ### Parameters - **mch_id** (string) - Required - Merchant ID. - **callback_url** (string) - Required - The URL to redirect to after authorization. - **type** (string) - Required - Type of login (e.g., 'snsapi_userinfo'). - **params** (object) - Optional - Additional parameters. - **key** (string) - Required - API key for authentication. ### Request Example ```javascript let result = await WxLogin.getOauthUrlAsync(mch_id, callback_url, type, params, key); console.log(result); ``` ### Response #### Success Response (200) - **result** (object) - The authorization URL and related information. ``` -------------------------------- ### Get WeChat Face Pay Auth Info Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Retrieves the authorization information for WeChat face-to-face payments. This includes parameters needed to initiate the face payment process. ```java FacePayAuthInfoBiz facePayAuthInfo = WxPay.getFacePayAuthInfo(mchId, "门店ID", "门店名称", "刷脸支付信息", "设备ID",null, null, null, key); ``` -------------------------------- ### Initialize WxPay for WeChat Payments Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JS-SDK/README.md Import the WxPay object to initiate WeChat payment functionalities. ```js //导入微信支付对象 import {WxPay} from 'yungouos-pay-sdk' ``` -------------------------------- ### Mini Program Payment (Sync) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Use this for synchronous mini-program payments for individuals/businesses. It requires constructing success and fail handlers before calling wx.requestPayment. ```javascript let result =await WxPay.minAppPayAsync(out_trade_no, total_fee, mch_id, body, openId, app_id, attach, notify_url, auto, auto_node, config_no, biz_params, payKey); let data=result.minPayParam; if(data==null||data==''||data==undefined){ console.log("支付失败"); return; } let minPayParam = JSON.parse(data); //构建支付成功方法 minPayParam.success = (response) => { if (response.errMsg == 'requestPayment:ok') { //支付成功 console.log("小程序支付成功"); } } //构建支付失败方法 minPayParam.fail = (response) => { if (response.errMsg == 'requestPayment:fail cancel') { //取消支付 console.log("取消支付"); } } //拉起小程序支付界面 wx.requestPayment(minPayParam); ``` -------------------------------- ### QQ Mini Program Pay (Individual/Enterprise - Sync) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Handles synchronous QQ Mini Program payments for individuals or enterprises. It requires constructing success and fail handlers for the payment response. ```javascript let result =await WxPay.qqPayAsync(app_id,access_token,out_trade_no, total_fee, mch_id, body,attach, notify_url, return_url, auto, auto_node, config_no, biz_params,payKey); let minPayParam=result.minPayParam; if(minPayParam==null||minPayParam==''||minPayParam==undefined){ console.log("支付失败"); return; } //构建支付成功方法 minPayParam.success = (response) => { if (response.errMsg == 'requestWxPayment:ok') { //支付成功 console.log("小程序支付成功"); } } //构建支付失败方法 minPayParam.fail = (response) => { if (response.errMsg == 'requestWxPayment:fail cancel') { //取消支付 console.log("取消支付"); } } //拉起小程序支付界面 qq.requestWxPayment(minPayParam); ``` -------------------------------- ### Get WeChat Authorization URL Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Generates a URL for WeChat authorization. Requires merchant ID, redirect URI, authorization type, optional JSON parameters, and the merchant secret. ```java WxApi.getWxOauthUrl(商户号, 授权结束后返回地址, 类型, 额外参数json字符串, 商户密钥); ``` -------------------------------- ### WeChat Mini Program Payment V3 (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Initiate a native WeChat Mini Program payment asynchronously. The payment parameters are returned and then used to invoke `wx.requestPayment` with success and fail handlers. ```js WxPay.minAppPayV3(out_trade_no, total_fee, mch_id, body, open_id,app_id, attach, notify_url, auto, auto_node, config_no, biz_params, payKey).then((response)=>{ //接口返回结果 if(response.code!=0||response.data==null){ console.log("支付失败"); return; } let minPayParam=response.data; if(minPayParam==null||minPayParam==''||minPayParam==undefined){ console.log("支付失败"); return; } //构建支付成功方法 minPayParam.success = (response) => { if (response.errMsg == 'requestPayment:ok') { //支付成功 console.log("小程序支付成功"); } } //构建支付失败方法 minPayParam.fail = (response) => { if (response.errMsg == 'requestPayment:fail cancel') { //取消支付 console.log("取消支付"); } } //拉起小程序支付界面 wx.requestPayment(minPayParam); }); ``` -------------------------------- ### Get WeChat Authorization URL Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Generates a WeChat authorization URL for OAuth. Requires merchant ID, callback URL, type, parameters (including secret key), and merchant key. ```java String mch_id="商户号"; String callback_url="http://www.yungouos.com/oauth"; String type="mp-base"; JSONObject params=new JSONObject(); params.put("key", "123456"); String key="商户密钥"; String oauthUrl = WxApi.getWxOauthUrl(mch_id, callback_url, type, params, key); ``` -------------------------------- ### Import SDK Components Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Import necessary components from the SDK. You can import specific modules or all available modules as needed. ```js //可按需导入 import {WxPay,AliPay,Finance,Merge,Order,PaySignUtil,PayBlack,WxLogin} from 'yungouos-pay-uniapp-sdk' ``` -------------------------------- ### Initiate Order Refund (WeChat) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Starts a refund process for a WeChat payment. Requires order details, merchant ID, custom refund ID, refund amount, description, and callback URL. ```java WxPay.orderRefund(订单号, 微信支付商户号,自定义退款单号,退款金额,退款描述,异步回调地址,商户密钥); ``` -------------------------------- ### QQ Mini Program Payment (Personal, Sync) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Generates parameters for QQ mini-program payments for personal accounts and navigates to the payment mini-program. Note the fixed appId and path for the payment mini-program. ```javascript let params = WxPay.qqPayParams(out_trade_no, total_fee, mch_id, body, app_id, attach, title, notify_url, auto, auto_node, config_no, biz_params, payKey); qq.navigateToMiniProgram({ appId: '1112112167',//支付收银小程序的appid 固定值 不可修改 path: '/pages/pay/pay',//支付页面 固定值 不可修改 extraData: params,//携带的参数 success(res) { console.log("小程序拉起成功"); }, fail(res) { } }); ``` -------------------------------- ### WeChat Mini Program Payment V3 (Synchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Initiate a native WeChat Mini Program payment synchronously for individuals, sole proprietors, or enterprises. This method prepares the payment parameters for the `wx.requestPayment` API. ```js let result =await WxPay.minAppPayV3Async(out_trade_no, total_fee, mch_id, body, open_id,app_id, attach, notify_url, auto, auto_node, config_no, biz_params, payKey); let minPayParam=response.data; if(minPayParam==null||minPayParam==''||minPayParam==undefined){ console.log("支付失败"); return; } //构建支付成功方法 minPayParam.success = (response) => { if (response.errMsg == 'requestPayment:ok') { //支付成功 console.log("小程序支付成功"); } } //构建支付失败方法 minPayParam.fail = (response) => { if (response.errMsg == 'requestPayment:fail cancel') { //取消支付 console.log("取消支付"); } } //拉起小程序支付界面 wx.requestPayment(minPayParam); ``` -------------------------------- ### Alipay Scan to Pay Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Initiates an Alipay scan-to-pay transaction. Supports various parameters including order details, amounts, merchant info, callback URLs, and optional business features like Huabei installments. ```java AliPay.nativePay(订单号,支付金额,支付宝商户号,商品描述,返回类型,应用app_id,附加数据,异步回调地址,同步回调地址,,分账配置单号,是否自动分账,自动分账节点,花呗分期业务,附加业务参数,商户密钥); ``` -------------------------------- ### Mini Program Payment (Async) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Handles asynchronous mini-program payments for individuals/businesses. It uses a .then() block to process the response and then constructs payment handlers. ```javascript WxPay.minAppPay(out_trade_no, total_fee, mch_id, body, openId, app_id, attach, notify_url, auto, auto_node, config_no, biz_params, payKey).then((response)=>{ //接口返回结果 if(response.code!=0||response.data==null){ console.log("支付失败"); return; } let result=response.data; let data=result.minPayParam; if(data==null||data==''||data==undefined){ console.log("支付失败"); return; } let minPayParam = JSON.parse(data); //构建支付成功方法 minPayParam.success = (response) => { if (response.errMsg == 'requestPayment:ok') { //支付成功 console.log("小程序支付成功"); } } //构建支付失败方法 minPayParam.fail = (response) => { if (response.errMsg == 'requestPayment:fail cancel') { //取消支付 console.log("取消支付"); } } //拉起小程序支付界面 wx.requestPayment(minPayParam); }); ``` -------------------------------- ### Import SDK Modules Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Import specific modules or the entire SDK into your project. You can import modules as needed. ```js //可按需导入 import {WxPay,AliPay,Finance,Merge,Order,PaySignUtil,PayBlack,WxLogin} from 'yungouos-pay-node-sdk' ``` -------------------------------- ### 调用微信支付接口 Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-WxApp-SDK/README.md 使用wxPayUtil.toPay方法发起支付请求,需要提供订单号、金额、商品描述、回调URL等参数。支付结果将通过回调函数返回。 ```javascript wxPayUtil.toPay(out_trade_no,total_fee,body,notify_url,attach,title,(response)=>{ console.log(response); //您的业务 }); ``` -------------------------------- ### Import SDK Components Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JS-SDK/README.md Import necessary components from the SDK into your project. Components can be imported individually or as needed. ```js //可按需导入 import {WxPay,AliPay,Finance,Merge,Order,PaySignUtil,PayBlack,WxLogin} from 'yungouos-pay-sdk' ``` -------------------------------- ### WeChat Payment Code Pay Example Source: https://context7.com/yungouos/yungouos-pay-sdk/llms.txt Handles WeChat payment using a user's payment code, suitable for offline scenarios like cash registers. The `auth_code` is the user's 18-digit payment code. A `code` of '1' indicates success, while '2' means payment is in progress and requires polling. ```java import com.yungouos.pay.wxpay.WxPay; import com.yungouos.pay.entity.CodePayBiz; // 付款码支付示例 String out_trade_no = "ORDER_" + System.currentTimeMillis(); String total_fee = "0.01"; String mch_id = "YOUR_MCH_ID"; String body = "付款码支付-测试商品"; String auth_code = "134567890123456789"; // 用户付款码(18位纯数字,以10-15开头) String app_id = null; String attach = "附加数据"; String receipt = "0"; // 是否开具电子发票 0:否 1:是 String notify_url = "https://your-domain.com/pay/notify"; String config_no = null; String auto = "0"; String auto_node = null; BizParams bizParams = null; String key = "YOUR_PAY_KEY"; try { CodePayBiz result = WxPay.codePay(out_trade_no, total_fee, mch_id, body, auth_code, app_id, attach, receipt, notify_url, config_no, auto, auto_node, bizParams, key); System.out.println("支付状态:" + result.getCode()); // code=1表示支付成功,code=2表示支付中需要轮询 if ("1".equals(result.getCode())) { System.out.println("支付成功,支付单号:" + result.getPayNo()); } } catch (PayException e) { System.out.println("支付失败:" + e.getMessage()); } ``` -------------------------------- ### Finance: Initiate Distribution Payment (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Initiates a distribution payment and handles the result asynchronously via a promise. ```APIDOC ## Finance: Initiate Distribution Payment (Asynchronous) ### Description Initiates a distribution payment and handles the result asynchronously using a promise. ### Method POST (Assumed, based on SDK method naming convention) ### Endpoint `/api/finance/pay/send` (Assumed) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **mch_id** (string) - Required - The merchant ID. - **ps_no** (string) - Required - The payment slip number. - **description** (string) - Required - Description of the payment. - **payKey** (string) - Required - The payment key. ### Request Example ```json { "mch_id": "merchant_abc", "ps_no": "ps_11223", "description": "Distribution payment", "payKey": "your_pay_key" } ``` ### Response #### Success Response (200) - **response** (object) - The response from the distribution payment gateway. #### Response Example ```json { "response": { ... } } ``` ``` -------------------------------- ### WeChat Mini Program Pay (V3) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JAVA-SDK/README.md Returns parameters required for WeChat mini program payments. The mini program should use `wx.requestPayment` to initiate the payment. This version is for native mini program payments. ```java JSONObject minAppPay = WxPay.minAppPayV3(System.currentTimeMillis()+"", "0.01", mchId, "小程序支付演示", "o-_-itxeWVTRnl-iGT_JJ-t3kpxU“,“wxa1445dsad1wr54ca”,null, null,null,null,null,null,key); ``` -------------------------------- ### Computer Website Pay (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-Node-SDK/README.md Initiates a payment for computer websites and handles the result asynchronously via a promise. ```APIDOC ## Computer Website Pay (Asynchronous) ### Description Initiates a payment for computer websites and handles the result asynchronously via a promise. ### Method POST (Assumed, based on SDK method naming) ### Endpoint Not specified, SDK method `AliPay.webPay` is used. ### Parameters - **out_trade_no** (string) - Required - The unique order number. - **total_fee** (string) - Required - The total amount of the order. - **mch_id** (string) - Required - Merchant ID. - **body** (string) - Required - The description of the goods. - **app_id** (string) - Required - The application ID. - **attach** (string) - Optional - Extended information. - **notify_url** (string) - Required - Asynchronous callback URL. - **return_url** (string) - Required - Synchronous return URL. - **hbfq_num** (string) - Optional - Huabei installment number. - **hbfq_percent** (string) - Optional - Huabei installment percentage. - **biz_params** (object) - Optional - Business parameters. - **payKey** (string) - Required - Payment key. ### Request Example ```javascript AliPay.webPay(out_trade_no, total_fee, mch_id, body, app_id, attach, notify_url, return_url, hbfq_num, hbfq_percent, biz_params, payKey).then((response) => { console.log(response); }); ``` ### Response (Asynchronous response from the computer website payment) ``` -------------------------------- ### Finance - Initiate Profit Distribution Payment (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-JS-SDK/README.md Initiates a profit distribution payment asynchronously using Promises. ```APIDOC ## Finance - Initiate Profit Distribution Payment (Asynchronous) ### Description Initiates a profit distribution payment asynchronously using Promises. ### Method POST (Assumed, based on SDK method name) ### Endpoint `/api/finance/sendPay` (Assumed, based on SDK method name) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **mch_id** (string) - Required - Merchant ID. - **ps_no** (string) - Required - Profit distribution service number. - **description** (string) - Optional - Description of the payment. - **payKey** (string) - Required - Payment key. ### Request Example ```json { "mch_id": "merchant456", "ps_no": "pservice001", "description": "Distribution payment", "payKey": "your_pay_key" } ``` ### Response #### Success Response (200) - **response** (object) - The result of initiating the profit distribution payment. #### Response Example ```json { "response": { ... } } ``` ``` -------------------------------- ### Finance: Initiate Distribution Payment (Synchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Initiates a distribution payment and returns the result synchronously. ```APIDOC ## Finance: Initiate Distribution Payment (Synchronous) ### Description Initiates a distribution payment and returns the result synchronously. ### Method POST (Assumed, based on SDK method naming convention) ### Endpoint `/api/finance/pay/send` (Assumed) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **mch_id** (string) - Required - The merchant ID. - **ps_no** (string) - Required - The payment slip number. - **description** (string) - Required - Description of the payment. - **payKey** (string) - Required - The payment key. ### Request Example ```json { "mch_id": "merchant_abc", "ps_no": "ps_11223", "description": "Distribution payment", "payKey": "your_pay_key" } ``` ### Response #### Success Response (200) - **result** (object) - The result of the distribution payment initiation. #### Response Example ```json { "result": { ... } } ``` ``` -------------------------------- ### QQ Mini Program Pay Params (Individual) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Generates parameters for QQ Mini Program payments for individuals. This function prepares the necessary data to navigate to the payment mini-program. ```javascript let params = WxPay.qqPayParams(out_trade_no, total_fee, mch_id, body,app_id, attach, title, notify_url, auto, auto_node, config_no, biz_params, payKey); qq.navigateToMiniProgram({ appId: '1112112167',//支付收银小程序的appid 固定值 不可修改 path: '/pages/pay/pay',//支付页面 固定值 不可修改 extraData: params,//携带的参数 success(res) { console.log("小程序拉起成功"); }, fail(res) { } }); ``` -------------------------------- ### Initiate Share Refund (Async) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Asynchronously initiates a refund for a shared payment. Requires refund details and reason. ```javascript Finance.shareReturn(out_return_no, ps_no, mch_id, money, reason, notify_url, key).then((response)=>{ //发起分账回退结果 console.log(response); }); ``` -------------------------------- ### Computer Website Payment (Asynchronous) Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-UniApp-SDK/README.md Initiates a payment for computer websites and handles the result asynchronously via a promise. ```APIDOC ## Computer Website Payment (Asynchronous) ### Description Initiates a payment for computer websites and handles the result asynchronously using a promise. ### Method POST (Assumed, based on SDK method naming convention) ### Endpoint `/api/pay/web` (Assumed) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **out_trade_no** (string) - Required - The unique order number. - **total_fee** (string) - Required - The total amount of the order. - **mch_id** (string) - Required - The merchant ID. - **body** (string) - Required - The description of the goods. - **app_id** (string) - Required - The application ID. - **attach** (string) - Optional - Attached information. - **notify_url** (string) - Required - The URL to receive asynchronous notifications. - **return_url** (string) - Required - The URL to redirect after payment. - **hbfq_num** (string) - Optional - Huabei installment number. - **hbfq_percent** (string) - Optional - Huabei installment percentage. - **biz_params** (object) - Optional - Business-specific parameters. - **payKey** (string) - Required - The payment key. ### Request Example ```json { "out_trade_no": "order_12345", "total_fee": "100.00", "mch_id": "merchant_abc", "body": "Product Name", "app_id": "app_xyz", "attach": "user_data", "notify_url": "https://example.com/notify", "return_url": "https://example.com/return", "hbfq_num": "3", "hbfq_percent": "25", "biz_params": {}, "payKey": "your_pay_key" } ``` ### Response #### Success Response (200) - **response** (object) - The response from the payment gateway. #### Response Example ```json { "response": { ... } } ``` ``` -------------------------------- ### 处理支付回调与全局数据存储 Source: https://github.com/yungouos/yungouos-pay-sdk/blob/master/YunGouOS-WxApp-SDK/README.md 在app.js的onShow方法中处理支付回调信息,包括支付状态和订单号,并将其存储在globalData中供其他页面使用。 ```javascript if (options == null || options == '' || options.referrerInfo == null || options.referrerInfo=='') { return; } let extraData=options.referrerInfo.extraData; if(extraData){ //不管成功失败 先把支付结果赋值 this.globalData.payStatus=extraData.code==0?true:false; if(extraData.code!=0){ wx.showToast({ title: extraData.msg,//错误提示 icon: 'none', duration: 3000 }); return; } //支付成功 this.globalData.orderNo=extraData.data.orderNo; } ```