npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bluejj/open-sdk-js

v2.0.5

Published

该 SDK 采用 CommonJS 规范,可通过 `require` 引入。 如果前端采用 Vite,可通过 `vite-plugin-node` 插件进行引入。

Downloads

97

Readme

使用说明

该 SDK 采用 CommonJS 规范,可通过 require 引入。 如果前端采用 Vite,可通过 vite-plugin-node 插件进行引入。

初始化微信登陆(前端)

初始化微信登陆,可通过 initWechatLogin 方法实现,需要传递的参数如下:

  • appkey:蓝景开放平台的 appkey
  • container_id:需要展示二维码的容器 ID
  • redirect_uri:登陆成功后的回调地址
const Open = require('@bluejj/open-sdk-js');

const wechatLogin = await Open.initWechatLogin({
  appkey: "ask91k2kasdk"
})

// 在页面文件中调用 initLogin 即可初始化登录二维码
wechatLogin.initLogin({
  container_id: 'container',
  redirect_uri: 'https://backend.bluej.cn/api/user/wechat',
})

登陆成功后,后台服务会将 openid 作为路径参数拼接到回调地址上。

初始化微信支付(后端)

可通过 initWechatPay 方法实现微信支付的初始化

const open = require('@bluejj/open-sdk-js');
const WechatPay = await Open.initWechatPay({
  appkey: "ask91k2kasdk"
});

该方法同样返回一个实例,通过 WechatPay 实例,可以实现支付创建、订单查询、关闭等操作

创建预支付订单 - createPayment

所需参数:

  • mode:支付模式,可选 nativeh5,默认为 native 模式
  • out_trade_no:商户端的商品订单号
  • notify_url:支付结果的回调地址
  • description:商品描述
  • total:商品总价,单位为
  • app_name:可选,H5 模式下的网页名称
  • app_url:可选,H5 模式下的网页域名

调用示例:

const params = {
  description: '测试商品',
  out_trade_no: '1667879222',
  notify_url: 'https://open.bluej.cn/wechatpay/notify',
  total: 1
};

const result = await WechatPay.createPayment(params);

返回值:

createPayment 的返回值是一个 promise,需要通过 await 进行处理接收。

{
  code: 200,
  msg: '订单预支付信息创建成功',
  data: {
    status: 200,
    code_url: 'weixin://wxpay/bizpayurl?pr=PPlUDWZzz',
  },
};

前端可通过 code_url 生成支付二维码,用户支付后,系统将会将支付结果发送至 redirect_url

回调的返回值:

{
  code: 200,
  msg: '成功操作',
  data: {
    out_trade_no: '1667879222',
    trade_type: 'NATIVE',
    trade_state: 'SUCCESS',
    trade_state_desc: '支付成功',
    bank_type: 'OTHERS',
    payer: { openid: 'skS_SK10lsmCN91' },
    success_time: '2021-01-12T10:43:43+08:00',
    transaction_id: '4200000848202101120290526543'
    amount: { total: 1, payer_total: 1, currency: 'CNY', payer_currency: 'CNY' }
  },
};

查询订单 —— query

所需参数:

  • out_trade_no:商户订单号

调用示例:

const out_trade_no = '1667879222';
const result = await WechatPay.query(out_trade_no);

返回值:

{
  code: 200,
  msg: '成功操作',
  data: {
    out_trade_no: '1667879222',
    promotion_detail: [],
    trade_state: 'NOTPAY',
    trade_state_desc: '订单未支付',
  },
};

关闭订单 —— close

所需参数:

  • out_trade_no:商户订单号

调用示例:

const out_trade_no = '1667879222';
const result = await WechatPay.close(out_trade_no);

返回值:

{
  status: 204
}