wechatpay.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const express = require('express');
  2. const router = express.Router();
  3. const OAuth = require('wechat-oauth');
  4. const tenpay = require('tenpay');
  5. const config = {
  6. appid: 'wxb558057b16b95dd5',
  7. mchid: '1391101602',
  8. partnerKey: 'WLfN6xZt60JL2Pj1HFb72VA48IPofN3n'
  9. };
  10. const wechatApi = new tenpay(config);
  11. // const oauthClient = new OAuth('wxb558057b16b95dd5', '46237a17fbc57f5ebc5cc93c2b8cc505');
  12. const oauthClient = new OAuth('wxae62986df7490c49', '68dfe0d7c768d650847b307700db04ef');
  13. /* router.get('/', async function (req, res, next) {
  14. let result = await api.micropay({
  15. out_trade_no: `testOrder${new Date().getTime()}`,
  16. body: 'Test order',
  17. total_fee: 100,
  18. auth_code: '46237a17fbc57f5ebc5cc93c2b8cc505'
  19. });
  20. console.log(result);
  21. }); */
  22. router.get('/', (req, res, next) => {
  23. let url = oauthClient.getAuthorizeURLForWebsite('http://www.1473.cn/wechatpay');
  24. console.log(url);
  25. res.send(url);
  26. })
  27. router.get('/wechatpay', (res, req, next) => {
  28. console.log(res);
  29. })
  30. module.exports = router;