uniapp+unicloud:unipay(v3支付)

v3安全性很高,需要签名,unipay解决了签名,所以直接用就可以

先看文档:

const path = require('path'); // 引入内置的path模块

const unipayIns = unipay.initWeixinV3({
  appId: 'your appId',
  mchId: 'your mchId',
  v3Key: 'you parterner key',
  appCertPath: path.resolve(__dirname, 'your appCertPath'),
  // appCertContent: "", 
  appPrivateKeyPath: path.resolve(__dirname, 'your appPrivateKeyPath'),
  // appPrivateKeyContent: "",
})

调起支付功能--文档

获取支付参数

unipayIns.getOrderInfo,此接口仅支持微信小程序、支付宝小程序、App 平台

根据接口要求入参就可以

详细自己看文档把

uni-app官网

注意这边appCertPath他文件结尾是pem 不是p12文件,当时我填错了找了很久才找到,因为v2是p12

我的代码:

const unipay = require('uni-pay');
exports.main = async (event, context) => {
	//這個path0,你原來用的是p12
	let path0 = path.resolve(__dirname, 'cert/apiclient_cert.pem')
	let path1 = path.resolve(__dirname, 'cert/apiclient_key.pem')
	const unipayIns = unipay.initWeixinV3({
		appId: appid, //小程序appid
		mchId: mchid, //微信商户号
		v3Key: key, //商户号的API密钥
		appCertPath: path0, //API 证书文件路径
		appPrivateKeyPath: path1 //私钥路径
	})
	// 付款
		//event为客户端上传的参数
		orderInfo = await unipayIns.getOrderInfo({
			openid: event.openid, //这个是客户端上传的用户的openid
			// subject: event.name, // 订单名称微信支付时不可填写此项
			body: event.body,
			outTradeNo: event.outTradeNo, //商户订单号
			totalFee: event.totalFee, // 金额,单位元,在上传过来的时候就已经*100了
			// 支付结果通知地址,没有该参数或者为空会报错,随便给了一个测试网址
			notifyUrl: 'https://pay.weixin.qq.com',
			tradeType: 'JSAPI',
			spbillCreateIp: context.CLIENTIP
			// attach: event.orderid, //备注,订单号或 长者id 在下一步通知中判断长度来确定
		})

相关推荐

  1. springboot3整合支付宝沙箱网页版

    2023-12-08 07:40:06       32 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-08 07:40:06       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-08 07:40:06       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-08 07:40:06       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-08 07:40:06       18 阅读

热门阅读

  1. Boost:asio多io_service,多线程run

    2023-12-08 07:40:06       31 阅读
  2. 使用单例模式+观察者模式实现参数配置实时更新

    2023-12-08 07:40:06       28 阅读
  3. 芯知识 | 什么是单片机语音芯片?

    2023-12-08 07:40:06       50 阅读
  4. GO设计模式——11、装饰器模式(结构型)

    2023-12-08 07:40:06       33 阅读
  5. TrustZone概述

    2023-12-08 07:40:06       39 阅读
  6. 生信数据分析高效Python代码

    2023-12-08 07:40:06       32 阅读
  7. TCP通讯

    TCP通讯

    2023-12-08 07:40:06      37 阅读
  8. arXiv学术速递笔记12.6

    2023-12-08 07:40:06       26 阅读