PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/widget/wechatpay/README.en.md

https://gitlab.com/Ltaimao/amazeui
Markdown | 93 lines | 73 code | 20 blank | 0 comment | 0 complexity | e7e73cc793e0fe89a46aea4f83a1282b MD5 | raw file
  1. # WechatPay
  2. ---
  3. WeChat JS SDK Example. **99% of a WechatPay project is on backend. If you want to use WechatPay in your project, please pay more attention to the backend.**
  4. **Please return the WeChat JS SDK and the authentication configuration from the backend**. See[WeChat official Docs](http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html) for more imformation.
  5. The WechayPay requrest making through JS SDK is only avaliable in WeChat. Please scan the QR code in Wechat to see the example.
  6. <div id="doc-wechat-pay-qr"></div>
  7. ---
  8. ## API
  9. ```javascript
  10. {
  11. "id": "",
  12. "className": "",
  13. "theme": "",
  14. "options": {},
  15. "content": {
  16. // Order imformation and signature
  17. "order": {
  18. "timestamp": "", // Signature timestamp.
  19. "nonceStr": "", // Signature random string.
  20. "package": "", // The prepay_id returned by the unified order API
  21. "signType": "", // Encryption method
  22. "paySign": "" // Signature
  23. },
  24. "title": "" // Texts on button
  25. }
  26. }
  27. ```
  28. ## Something Important
  29. ### JS SDK Authentication
  30. All the pages need JS-SDK should have configuration injected. Otherwise, JS-SDK will not be avaliable. See more details in [WechatPay API](http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html). Signature and other configurations can be made in server-side, and the details can be found in [Wechat Offical Docs](http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#JSSDK.E4.BD.BF.E7.94.A8.E6.AD.A5.E9.AA.A4).
  31. ```javascript
  32. wx.config({
  33. debug: true,
  34. appId: '', // Required. ID of offical account.
  35. timestamp: '', // Signature timestamp.
  36. nonceStr: '', // Signature random train.
  37. signature: '' // Signature
  38. jsApiList: [
  39. 'chooseWXPay'
  40. ] // Required. The required JS API list.
  41. });
  42. ```
  43. ### Create order with WechatPay Unified Order API
  44. See more details in [Official Docs](http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1)
  45. ### Generate Signature
  46. See more details in [Wechat signature algorithm](http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_3)
  47. ### Send pay request
  48. ```
  49. wx.chooseWXPay({
  50. timestamp: 0, // Time stamp. Though "timestamp" in jssdk are all in lowercase, the "S" in the "timeStamp" used to create signature is capitalized.
  51. nonceStr: '', // The random string. At most 32 bits.
  52. package: '', // The prepay_id returned by the unified order API.
  53. signType: 'MD5', // Encryption method. Default method is 'SHA1'. The latest version require to use 'MD5'.
  54. paySign: '', // Signature.
  55. });
  56. ```
  57. <script>
  58. (function($) {
  59. var QRCode = $.AMUI.qrcode;
  60. $(function() {
  61. var qrnode = new QRCode({
  62. render: 'canvas',
  63. correctLevel: 0,
  64. text: 'http://amazeui.org/widgets/wechatpay',
  65. width: 200,
  66. height: 200,
  67. background: '#fff',
  68. foreground: '#000'
  69. });
  70. $('#doc-wechat-pay-qr').html(qrnode);
  71. });
  72. })(window.jQuery);
  73. </script>