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

@wecity/weapps-plugin-citycode-callback

v0.0.3

Published

功能: 1.回调的能力 2.回调后开启消息订阅的能力,当小程序设置中关闭了消息订阅,则会先去提醒用户开启,若开启了,则会调起消息订阅的授权弹框。

Downloads

6

Readme

城市码-回调 sdk

功能: 1.回调的能力 2.回调后开启消息订阅的能力,当小程序设置中关闭了消息订阅,则会先去提醒用户开启,若开启了,则会调起消息订阅的授权弹框。

使用方法:

1. 导入并创建实例

import { cbClass } from "@govcloud/weapps-plugin-city-code-utils";
cb = new cbClass({
  duration: 3000, // 轮询时间(ms),默认3s
  timeout: 15000, // 超时时间(ms),不传则进行超时处理
});

2. 启动轮询

调用方式

cb.onScanWaiting(() => {
  //...
})
  .then((res) => {
    // ...回调成功处理
  })
  .catch((res) => {
    // ...回调失败处理
  });

举例:

cb.onScanWaiting(() =>
  app.http.default({
    url: "/ebus/citycode/ext/callback/mock/polling",
    method: "POST",
    data: { cityCodeId },
  })
)
  .then((res) => {
    console.log("扫码回调的最终结果-成功", res);
    $page.handler.refreshQrCode();
  })
  .catch((res) => {
    console.log("扫码回调的最终结果-失败", res);
  });

cb.onScanWaiting 需传入一个方法,一般是 http 请求,并且该方法返回的是模版数据,必须是如下结构:

模版数据结构

模版数据中: 当 templateType = 0 时,回调结束将直接 resolve, 当 templateType 为其他值时, 回调结束后将会先跳转到回调模版页面,点击按钮后会调起消息订阅的触发流程,其中 tmplIds 是模版 id,目前仅支持一次订阅 3 个。

{
    "bizData": {
        "templateType": ,                            //... 模版类型
        "document": {
        "desc": "你的城市码已被门禁于2018年3月26日扫描",  // 模版页面描述
        "button": "确定"                              // 模版页面按键文字
        },
        "msgTmpl": {
            "tmplIds": [
                                                      //... 模版id
            ],
            "subscribe": true                         // 是否需要订阅消息
        }
    },
    //...
}

举例如下:

{
  "cityCodeAppId": "A00D",
  "cityCodeId": "xxx",
  "bizData": {
    "templateType": 0
    //...
  }
}

{
  "cityCodeAppId": "A00D",
  "cityCodeId": "xxxx",
  "bizData": {
    "templateType": 4,
    "document": {
        "desc": "你的城市码已被门禁于2020年10月1日扫描",
        "button": "确定"
    },
    "msgTmpl": {
    "tmplIds": ["xxxxx"],
    "subscribe": true
    }
  }
}

返回的结果

注意:当回调成功后,则会在.then 中输出结果,即使订阅消息失败 只有在回调失败或者入参错误等,才会 reject 出来

例如:成功时.then 中的结果有以下几种形式:

  1. 当 templateType = 0 时的回调,即不需要进行消息订阅的后续行为,则返回的结果就是回调结果的 body
  2. 当 templateType != 0 时,且订阅消息均成功时:
{
    esScanRes: {
        bizData : {
            document: {
                //...
            },
            msgTmpl: {
                //...
              }
        }
    },
    subscribRes: {
        res: {
            ZdxKTIrKR_bedh1K3aed2ZunNOB_EHqSe0i0oCT8hWM: "accept",
            d9CZgtdL5rifendw2SsekvhoZj1mEexKnFiGga0oC6s: "accept"
        }
    }
}

其中esScanRes是回调请求的结果。 subscribRes是订阅的结果,若订阅成功,则subscribRes会返回res,res里面是订阅的结果;若订阅失败,则会返回errMsg,显示错误来源。

2. 关闭轮询

cb.offScanWaiting();

3. 关闭轮询后,重新开启轮询需要先调用 reset

cb.reset();