{"id":15631056,"url":"https://github.com/0x5e/react-native-alipay","last_synced_at":"2025-04-05T14:03:07.036Z","repository":{"id":46157824,"uuid":"105547794","full_name":"0x5e/react-native-alipay","owner":"0x5e","description":"Alipay SDK for React Native. Support RN \u003e= 0.47.","archived":false,"fork":false,"pushed_at":"2023-06-06T09:23:44.000Z","size":26980,"stargazers_count":198,"open_issues_count":31,"forks_count":86,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-27T11:01:28.522Z","etag":null,"topics":["alipay","alipaysdk","android","ios","react-native","sdk"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0x5e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-02T14:59:39.000Z","updated_at":"2024-06-15T04:52:19.000Z","dependencies_parsed_at":"2024-06-18T18:40:02.148Z","dependency_job_id":"dc62148a-0ab2-41f8-80ae-3597cf7e9e4f","html_url":"https://github.com/0x5e/react-native-alipay","commit_stats":{"total_commits":49,"total_committers":9,"mean_commits":5.444444444444445,"dds":"0.26530612244897955","last_synced_commit":"c408268cd1f2a02f87ef2634173a6225a925db7f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x5e%2Freact-native-alipay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x5e%2Freact-native-alipay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x5e%2Freact-native-alipay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x5e%2Freact-native-alipay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0x5e","download_url":"https://codeload.github.com/0x5e/react-native-alipay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246989742,"owners_count":20865330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alipay","alipaysdk","android","ios","react-native","sdk"],"created_at":"2024-10-03T10:38:49.063Z","updated_at":"2025-04-05T14:03:07.016Z","avatar_url":"https://github.com/0x5e.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# react-native-alipay\n\n[![NPM Version](https://img.shields.io/npm/v/@0x5e/react-native-alipay.svg)](https://npmjs.org/package/@0x5e/react-native-alipay)\n[![Dependency Status](https://img.shields.io/david/0x5e/react-native-alipay.svg)](https://david-dm.org/0x5e/react-native-alipay)\n[![Build Status](https://img.shields.io/travis/0x5e/react-native-alipay/master.svg)](https://travis-ci.org/0x5e/react-native-alipay)\n[![License](https://img.shields.io/npm/l/@0x5e/react-native-alipay.svg)](./LICENSE)\n\nAlipay SDK for React Native. Support mobile webpage url payment. Support RN \u003e= 0.47.\n\nNative AlipaySDK library ([download page](https://docs.open.alipay.com/54/104509)):\n\n- iOS: v15.5.9 (2018.11.26)\n- Android: v15.5.9 (2018.11.26)\n\n## Features\n\n- [x] 快捷登录授权（ https://docs.open.alipay.com/218/105327/ ）\n- [x] APP支付（ https://docs.open.alipay.com/204/105465/ ）\n- [x] 手机网站转APP支付（ https://docs.open.alipay.com/204/105695/ ）\n- [x] 参数签名（ https://docs.open.alipay.com/291/106118/ ）\n\n## Requirement\n\n- React Native \u003e= 0.20\n- iOS \u003e= 7.0\n- Android \u003e= 4.4 (API 19)\n\n## Getting started\n\n`$ yarn add @0x5e/react-native-alipay`\n\n### Native module installation\n\n- [iOS Setup](./docs/ios-setup.md)\n- [Android Setup](./docs/android-setup.md)\n\n## API Documentation\n\n### Alipay.authWithInfo(infoStr)\n\n- `infoStr` {String} Auth request info in query string format. Must be signed before use. See [Auth request params description](https://docs.open.alipay.com/218/105327).\n\nReturns object with following fields:\n\n|field|type|description|\n|:----|:---|:----------|\n|`resultStatus`|String|See [Response code description](#response-code-description)|\n|`result`|String|Result data in query string format|\n|`memo`|String|Reserved field, nothing|\n\nThe `result` data has following fields:\n\n|field|type|description|\n|:----|:---|:----------|\n|`success`|Boolean|`true` if succeed|\n|`result_code`|String|Result code|\n|`auth_code`|String|Authorization code|\n|`user_id`|String|User id|\n\nThe `result_code` description:\n\n|code|description|\n|:----|:----------|\n|200|业务处理成功，会返回authCode|\n|202|系统异常，请稍后再试或联系支付宝技术支持|\n|1005|账户已冻结，如有疑问，请联系支付宝技术支持|\n\nExample code:\n\n```javascript\nimport QueryString from 'query-string';\nimport Alipay from '@0x5e/react-native-alipay';\n\n// 快捷登录授权\ntry {\n  let infoStr = 'apiname=com.alipay.account.auth\u0026method=alipay.open.auth.sdk.code.get\u0026app_id=xxxx\u0026app_name=mc\u0026biz_type=openservice\u0026pid=xxxx\u0026product_id=APP_FAST_LOGIN\u0026scope=kuaijie\u0026target_id=xxxx\u0026auth_type=AUTHACCOUNT\u0026sign_type=RSA2\u0026sign=xxxx'; // get from server, signed\n  let response = await Alipay.authWithInfo(infoStr);\n  console.info(response);\n\n  let { resultStatus, result, memo } = response;\n  let { success, result_code, auth_code, user_id } = QueryString.parse(result);\n\n  // TODO: ...\n\n} catch (error) {\n  console.error(error);\n}\n```\n\n### Alipay.setAlipaySandbox(isSandbox)\n\n- `isSandbox` {boolean} Whether to open sandbox. Must be payed before use. See [使用沙箱环境](https://docs.open.alipay.com/200/105311)\n\n### Alipay.pay(orderStr)\n\n- `orderStr` {String} Order info in query string format. Must be signed before use. See [App payment request params description](https://docs.open.alipay.com/204/105465/).\n\nReturns object with following fields:\n\n|field|type|description|\n|:----|:---|:----------|\n|`resultStatus`|String|See [Response code description](#response-code-description)|\n|`result`|String|Result data in json string format|\n|`memo`|String|Reserved field, nothing|\n\nThe `result` data has following fields:\n\n|field|type|description|\n|:----|:---|:----------|\n|`code`|String|结果码，具体见[公共错误码](https://docs.open.alipay.com/common/105806)|\n|`msg`|String|处理结果的描述，信息来自于code返回结果的描述|\n|`app_id`|String|支付宝分配给开发者的应用Id|\n|`out_trade_no`|String|商户网站唯一订单号|\n|`trade_no`|String|该交易在支付宝系统中的交易流水号|\n|`total_amount`|String|该笔订单的资金总额，单位为RMB-Yuan|\n|`seller_id`|String|收款支付宝账号对应的支付宝唯一用户号|\n|`charset`|String|编码格式|\n|`timestamp`|String|时间|\n\nExample code:\n\n```javascript\nimport Alipay from '@0x5e/react-native-alipay';\n\n// APP支付\ntry {\n  // 打开沙箱\n  Alipay.setAlipaySandbox(true)\n  let orderStr = 'app_id=xxxx\u0026method=alipay.trade.app.pay\u0026charset=utf-8\u0026timestamp=2014-07-24 03:07:50\u0026version=1.0\u0026notify_url=https%3A%2F%2Fapi.xxx.com%2Fnotify\u0026biz_content=%7B%22subject%22%3A%22%E5%A4%A7%E4%B9%90%E9%80%8F%22%2C%22out_trade_no%22%3A%22xxxx%22%2C%22total_amount%22%3A%229.00%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D\u0026sign_type=RSA2\u0026sign=xxxx'; // get from server, signed\n  let response = await Alipay.pay(orderStr);\n  console.info(response);\n\n  let { resultStatus, result, memo } = response;\n  let { code, msg, app_id, out_trade_no, trade_no, total_amount, seller_id, charset, timestamp } = JSON.parse(result);\n\n  // TODO: ...\n\n} catch (error) {\n  console.error(error);\n}\n```\n\n### Alipay.payInterceptorWithUrl(h5PayUrl)\n\n- `h5PayUrl` {String} The url string of mobile webpage payment. You may get it from webview. See [document](https://docs.open.alipay.com/204/105695/) for detail.\n\nReturns object with following fields:\n\n|field|type|description|\n|:----|:---|:----------|\n|`resultCode`|String|[返回码](#response-code-description)|\n|`returnUrl`|String|支付结束后应当跳转的url地址|\n\nExample code:\n\n```javascript\nimport Alipay from '@0x5e/react-native-alipay';\n\n// 手机网站转APP支付\ntry {\n  let h5PayUrl = 'https://wappaygw.alipay.com/service/rest.htm?_input_charset=utf-8\u0026format=xml\u0026partner=xxxx\u0026req_data=%3Cauth_and_execute_req%3E%3Crequest_token%3Exxxx%3C%2Frequest_token%3E%3C%2Fauth_and_execute_req%3E\u0026sec_id=MD5\u0026service=alipay.wap.auth.authAndExecute\u0026v=2.0\u0026sign=xxxx'; // get from webview, signed\n  let { resultCode, returnUrl } = await Alipay.payInterceptorWithUrl(h5PayUrl);\n  console.info(resultCode, returnUrl);\n} catch (error) {\n  console.error(error);\n}\n```\n\n### Alipay.sign(object, privateKey)\n\nIf you want to do client side signature instead of server side (not recommend), you can use this.\n\n- `object` {Object} Object to be signed. The `object.sign_type` can specify `RSA` (default) or `RSA2`.\n- `privateKey` {String} Private key in `PKCS#1` or `PKCS#8` format.\n\nNote: \n`PKCS#1` private key should have wrapped with `-----BEGIN RSA PRIVATE KEY-----` and `-----END RSA PRIVATE KEY-----`\n`PKCS#8` private key should have wrapped with `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----`\n\nReturns The query string with signature. See [Process of signature](https://docs.open.alipay.com/291/106118) for detail.\n\nExample code:\n\n```javascript\nimport Alipay from '@0x5e/react-native-alipay';\n\n// 签名\nlet params = {\n  app_id: 2183,\n  biz_content: '{\"scopes\":[\"auth_base\"],\"state\":\"init\"}',\n  method: 'alipay.user.info.auth',\n  timestamp: '2017-10-13 00:00:00',\n  version: '1.0',\n};\nlet privateKey = '-----BEGIN RSA PRIVATE KEY-----\\n' + ... + '\\n-----END RSA PRIVATE KEY-----';\nlet signedQuery = Alipay.sign(params, privateKey);\nconsole.info(signedQuery); // app_id=2183\u0026biz_content=%7B%22scopes%22%3A%5B%22auth_base%22%5D%2C%22state%22%3A%22init%22%7D\u0026method=alipay.user.info.auth\u0026sign_type=RSA\u0026timestamp=2017-10-13%2000%3A00%3A00\u0026version=1.0\u0026sign=xxxx\n```\n\n### Response code description\n\n|code|description|\n|:-----------|:----------|\n|9000|操作成功|\n|8000|正在处理中|\n|4000|操作失败|\n|5000|重复请求|\n|6001|用户中途取消|\n|6002|网络连接出错|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x5e%2Freact-native-alipay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0x5e%2Freact-native-alipay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x5e%2Freact-native-alipay/lists"}