Giter VIP home page Giter VIP logo

semipay's Introduction

SEMIPAY - 一个开源的个人收款解决方案

ENGLISH VERSION

欢迎使用 SEMIPAY,个人收款解决方案,只需在 Vercel 上简单配置即可轻松部署私有的支付系统。

它可以创建半自动个人收款系统,免去域名备案,资质审批,交易费用等种种问题。适合每分钟收款小于5笔的系统。

你也可以用著名的wechatyhttps://wechaty.js.org/来监听微信付款消息,实现全自动收款。一个考虑周全的自动收款系统相当复杂,而且有被微信封锁的风险,我就不细说了。

主要功能

  • ⚡ 通过 Vercel 一键免费部署,添加所需配置即可立即拥有自己的微信收款系统
  • 💬 支持tg机器人通知
  • 🎨 操作简单,在vercel edge config 更新配置即可立即生效
  • 🌈 安全开源,无需担心资金问题

演示

获取测试结账链接:https://payment-mauve.vercel.app

用法

准备好配置

  • 拷贝 examle.edge.conf.json 配置模板,初始化你的vercel edge config

  • 准备多张不同备注信息,固定金额的微信收款二维码,上传到网络(比如github, 比如对象存储服务器)

  • 拿到可以直接访问的URL后填入qrcode字段

  • 购买国内可用的域名(hostname),你也可以直接用vercel送的域名

  • 设置好tg机器人链接,密钥 和 支付站点的hostname

  • 设置好webhook 的地址,用于确认订单后的回调,请求样本如下所示:

curl -X POST <webhook>&token=<token> \n
-H "Content-Type: application/json" \n
-d '{"price":<price>,"user":"<user>","extra":"<extra>","uid":"<uid>","remark":"<remark>","timestamp":<timestamp>}'

# 比如

curl -X POST -H "Content-Type: application/json" -d '{"price": 10, "user": "[email protected]", "extra": "Extra information", "uid": "1234", "remark": "Payment for product X", "timestamp": 1622213957}' https://your-webhook-url.com?token=your-token
  • 请务必保证webhook可用,否则订单不会被确认

  • token生成:

// info 即需要签名的payload
const secret = process.env.SECRET;
// 按字母顺序排序
const text = Object.keys(info).sort().map(k=> info[k]).join(','); 
// 使用sha256加密信息
const token = createHmac('sha256', secret).update(text).digest('base64');

总之,代码都在这了,不用我多加解释。

设置vercel

以下 JSON 模板可供参考,用来设置 Vercel edge-config:

https://vercel.com/dashboard/stores/edge-config

{
  "qrcode": [
    {
      "url": "https://..co/storage/v1/object/public/static/five1.jpg",
      "remark": "five1",
      "price": 5
    },
    {
      "url": "https://..co/storage/v1/object/public/static/five2.jpg",
      "remark": "five2",
      "price": 5
    },
    {
      "url": "https://..co/storage/v1/object/public/static/five3.jpg",
      "remark": "five3",
      "price": 5
    }
  ],
  "webhook": "https://ok/api/wepaynotify?",
  "telegram": "https://api.telegram.org/botxxxx:xxxx/sendMessage?chat_id=xxx&",
  "hostname": "https://pay",
  "secret": "123"
}

开始使用

// 从你的业务服务器向支付服务器获取付款链接
const hostname = 'https://your.pay.domain';
// 准备信息
const info = {
    price: 5, // 价格,需要和你上面的qrcode数组price对应
    user: '[email protected]',
    extra: 'donate', // 额外信息,一般放商品id之类
    timestamp: Date.now() // 随便,简单防攻击而已
};

// 进行签名
// 获取密钥
const secret = process.env.SECRET;
// 按字母顺序排序
const text = Object.keys(info).sort().map(k=> info[k]).join(','); 
// 使用sha256加密信息
const token = createHmac('sha256', secret).update(text).digest('base64');

// 去支付服务器换付款链接
const checkout = await fetch(`${hostname}/api/checkout`, {
    method: 'post',
    body: JSON.stringify({...info, token})
}).then(res=>{
    if(res.status !== 200) throw new Error(res.status);
    return res;
}).then(res=>res.json());

// 付款链接
console.log(checkout);

// 用户点开checkout页面后,如果配置了tg机器人,则会收到消息
/**
  A checkout was placed 
    
    -user: demo@user.com
    -price: 5
    -remark: five1
    -extra: manual-5
    -uid: a3f65157-b9f5-49ad-95bf-7967200a3b38

    click here to confirm the payment
 * 
 * /
// 点击后即可确认订单,并调用webhook的地址发送确认消息

部署

通过一键式部署在 Vercel 上部署自己的支付网站:

Deploy with Vercel

二次开发

这是一个使用create-next-app快速启动的Next.js项目。

开始

首先,请运行开发服务器:

npm run dev
# 或者
yarn dev
# 或者
pnpm dev

使用您的浏览器打开 http://localhost:3000 来查看结果。

在Vercel上部署

部署Next.js应用程序的最简单方法是使用Next.js部署文档中介绍的Vercel平台,Vercel是Next.js的创造者。

更多细节请查阅我们的Next.js部署文档

semipay's People

Contributors

wanghsinche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.