//引入alipay sdk
const AliPaySdk = require('alipay-sdk').default
//引入alibapay form
const AlipayForm = require('alipay-sdk/lib/form').default
//初始化alipay 配置
const alipaySdk = new AliPaySdk({
appId: "2021000118667707", //appid
privateKey: "MIIEowIBAAKCAQEAlWo7zzOn84zGnisMgIW5w5gW1SmRqI4tTRNPGX/xjH+mozxw1GALn70LOOgRt7ldD49kW13LZASScS1sLYM9Pytsbm/3TNhXNpCkrghbhNbbOpHYwBjdWvpPAwEM19LRG8xTd/H3Uyq7eHrEE8WRJnEWHflYLysCZsxKMZ+tmApVarODUSFMmtrkdur7BOl1ydDkIF/cznW59L8o2aXrCHd+Gdy8J147lifCrhuKpI63O8IPl3yMQwXrOseuLHNM0d0Ya/pjHuGvZcPKIxqcynN/aP+Q8esmaR6OTPk6tcFC32c/UpG24TZaa8vH0fQa43v6FD0zWAvTpBmydkV3vwIDAQABAoIBADTgcKQmWsSlSFEHWRhOuuwOcd4kJOkqz7tcHv0eO0SGlFlmdWOjTdnNFCCieEq1rcpo65IuAmG2AIFPGt6MeGtXmbsHotQuJ8cmrzDrwj+jrdfvb26kHgopVTbx8zKZ5+jXiZ6EIgvrroa3o5Z/r5uUH8ihymR+6w2oNIWVReDtEW3FLZMTHirCRqdMJwvsTfchAVPRP8FejakqQIvomMPmGRFrLXJ0xIlBNhz8KLYs9nScgcoxz8fpa3+Lyu2jB9oWHEhq+6z9ju6x5turrKCQEqbh3RIuykLSxH5VPxMJopxB/ieiuBWZ6PdzyYNaXL0V3EFXUMsqe2lX9p1g5PkCgYEA9CuC/J5j27Hyk/Vhyuu+u3faJ9WdZxMfIcRx6mSwcuqC4xEhmWL7/SH2P0vhsSENGw90j5FN8kS84IcHJyFJzYJMu+8WId8S0MVwTyJCDFxxsKfH7px3jXToB1sJfPB3XmmZnSD6giqAYKY6E7a4FI+Ua8+S8Qfm1KWs5VJwt/sCgYEAnKd1AxHKPgQLaQDs6SV7MdgHh7ARv8y6/n2ATArqwU2j7js/lHuTc1udb9g3me6klPhWTciHenBye/j6XxfP18FoiGP0SrKqPGlqMLC/7KuL0nPyaqAc4/t0F7GfPO8lsTlMYFAn3t59vicL+xbJoLhA8n1Fj0CZqM0uYglKYA0CgYEAy74bGOyZ6tK71haluYuppgjGcwLeywm7qpOfcrT+P4XMHelHnhRorLrQHdUVyJYJt5DX9IyM/CG7cad6on42dVPK7+77Ctx3eNmnc4DkmCfzfjMis8rAP7tTef/PFQAaux9m3SSNpFwOr5dFUvne9NkyQhv9Qz8SsFJmyRxXjk0CgYAdwmomNSD4ewg34GchO2+V3nY/vqEAkMINSoYu6/wA0OENhs/jQz6VsZfNAYQ+h+lYK30ptaiXB/mXt4rIudtQH3vePS7RafORGm2D5m/vY/9h8Yjh3Jzgaop5XdLkXoIIktwBh/irDBVTJFPQVVnkYFxmNIocVqdaO/BNy3oHmQKBgGFo0zzJ430whoWgTZtkzu0xCDlc/Jfm/wExGBufhlmpimcfGqSjKX9cM/bXt2+1dBLyYvoHH7SnqP5FlVMROSX7L/o6MIiK3m00W0eI/6MEkgPjk4/fSYjC/dAH3aBU8gd+iwPeyFXRmg9uQhDOwW5MISoZ7RbwKNtjkA8jA/JV", //应用私钥
alipayPublicKey: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvVQjikYpv314W2DPhsbLkcSD/Bg7orFhVsIadcj+JN1EvlsK9TDVLD284sFaYC+u8XXvVPZZatq1XyzvvMLZa879oX95BkEc/OZ0ku1zY5WMdlIJ49lABVUAHni7c5WlFD5StscOGLNQCTzehO+EvGta/9aoCXLn/BRRcTZWiQOoC+U5wWBzkWrKvvGRSG4oR+5UQvx64ncnaDqziE08MIozBSw0HGOtg3boIatbSdSnl1aEQ+NzAjrwqpp5n5FmVDkIP4OOA0YZGk25z3HxAKz2TyWgWWyqubd/1PWmTiq6EIjenPaxq0rAwolFBaDwR3fqOdXjMnfZoQPr620R2QIDAQAB" ,//支付宝公钥:
gateway: "https://openapi.alipaydev.com/gateway.do", //支付宝沙箱测试网关
})
//引入express
const express = require('express')
const app = express()
const router = express.Router()
app.use('/api', router)
router.get('/pay', async (req, res) => {
const formData = new AlipayForm()
formData.setMethod('get')
formData.addField('returnUrl', 'http://www.baidu.com');//支付成功的回调
formData.addField('bizContent', {
outTradeNo: '1234678657434', //订单号
productCode: 'FAST_INSTANT_TRADE_PAY', //产品码
totalAmount: '500000',//金额
subject: '商品住宅', //标题
body: '小满的知识',//内容
});
//执行结果
const reult = await alipaySdk.exec('alipay.trade.page.pay',{},{ formData: formData });
res.json({url: reult})
});
// console.log(alipaySdk)
app.listen(9000, () => {
console.log('success, http://localhost:9000/api/pay')
})
node.js对接支付宝沙箱,实现支付即使到账
最新推荐文章于 2023-07-18 22:32:41 发布