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

@gov-api-package/subscribe-manager

v1.0.10

Published

订阅和订阅状态查询

Downloads

5

Readme

订阅API

一、在开发之前

1.1 配置域名

接入前请将此域名 https://zw.baidusmartapps.com 添加到request的合法域名中 | 域名 | 添加方式 | | ---- | ---- | | https://zw.baidusmartapps.com | 开发者后台->小程序管理->设置->开发设置->服务器域名->request的合法域名 |

1.2 获取订阅项的必要信息

每个可被订阅的服务项都有着唯一标识,通过服务项的唯一标识,开发者可以获取或者修改特定用户对于该服务项订阅状态。服务项的标识如下所示:

| 标识名称 | 标识字段 | | ---- | ---- | | 订阅标识 | sourceFlag | | 订阅ID | subscribeID |

二、接入

2.1 安装依赖

npm i @gov-api-package/subscribe-manager --save

2.2 API 使用

主动推订阅服务目前提供了获取订阅状态等API,具体如下表所示:

| API | 说明 | | ---- | ---- | | querySub | 获取订阅状态 | | addSub | 订阅 | | cancelSub | 取消订阅 | | toManage | 跳转订阅助手小程序 | | modifyIntervene | 修改干预信息 |

// 引入
import subscribeManager from '@gov-api-package/subscribe-manage';

2.2.1 获取订阅状态 querySub

API请求参数:

| 参数 | 类型 | 说明 | 是否必选 | | ---- | ---- | ---- | ---- | | sourceFlag | String | 订阅标识 | 是 | | openId | String | 小程序openId | 是 | | searchIntervene | String | 特征数据 | 否 |

API返回参数:

{
    "id":1,// subscribeID
    "status":1,// 0 未订阅 1订阅
    "main_title":"场景卡",
    "sub_title":"官方小程序",
    "intervene_type": 1,
    "intervene": [
        {
            "type": 1,
            "vaule": "110100"
        }
    ]
}

API使用示例:

/**
* 获取订阅状态
* @param {string} sourceFlag 订阅标识
* @param {string} openId 小程序openId
* @param {string} searchIntervene 特征数据
*/
subscribeManager.querySub(sourceFlag, openId, searchIntervene).then(res => {
    console.log(res);
    // 业务逻辑...
}).catch(err => {
    console.log(err);
});

2.2.2 订阅 addSub

API请求参数:

| 参数 | 类型 | 说明 | 是否必选 | 备注 | | ---- | ---- | ---- | ---- | ---- | | subscribeID | String | 订阅id | 是 | | | openId | String | 小程序openId | 是 | | | sourceFlag | String | 订阅标识 | 是 | | | interveneProps | Object | 特征类型和列表 | 否 | 仅在有特征数据时需要传入该数据 | | >>interveneProps.interveneType | Number | 特征类型 | 否 | 1(城市)2(省份)3(快递公司)4(运动员)...(仅在特征类型为1【城市】或者2【省份】且需要【代获取当前位置的特征列表】时,需要传入) | | >>interveneProps.intervene | Array. | 修改特征列表 | 否 | 当特征类型为非1【城市】且非2【省份】时,特征列表必须传入 | | >> >> interveneProps.intervene[].type | Number | 特征类型1(城市)2(省份)3(快递公司)4(运动员) | 是 | 传入type多个以逗号隔开 | |>> >> interveneProps.intervene[].value | String | 用英文逗号把vaule值连接起来 | 是 | 传入值,多个以逗号隔开 |

API返回参数:

API成功返回:

{
    "code":0,// 接口状态,0 操作成功
    "msg":"success",
    "data": {}
}

返回失败code错误码列表: | 错误码 | 错误详情 | | ---- | ---- | | 200000000 | 未获取到用户信息 | | 200000006 | 已订阅 | | 200000003 | 查询订阅号失败 | | 200000004 | 订阅失败 |

API使用示例:

/**
 * 订阅
 * @param {string} subscribeID 订阅id
 * @param {string} openId 小程序openId
 * @param {string} sourceFlag 订阅标识
 * @param {Object} interveneProps 特征类型和列表
 * @return {Promise} 请求对象
 */
subscribeManager.addSub(subscribeID, openId, sourceFlag, {
    intervene: [
        {
            "type": 1, // type 1是城市
            "value": "130000,130001,130002"
        },
        {
            "type": 2, // type 2是省份
            "value": "130000,130003"
        }
    ]
}).then(res => {
    console.log(res);
    // res.code 为 0 时接口正常
    // 业务逻辑...
    if(!res.code) {
        swan.showToast({
            title:'订阅成功',
            icon:'none'
        });
    }else{
        swan.showToast({
            title:'订阅失败',
            icon:'none'
        });
    }
}).catch(err => {
    swan.showToast({
        title:'订阅失败',
        icon:'none'
    });
});

2.2.3 取消订阅 cancelSub

API请求参数:

| 参数 | 类型 | 说明 | 是否必选 | 备注 | | ---- | ---- | ---- | ---- | ---- | | subscribeID | String | 订阅id | 是 | | | openId | String | 小程序openId | 是 | | | sourceFlag | String | 订阅标识 | 是 | |

API返回参数:

API返回成功:

{
    "code":0,// 接口状态,0 操作成功
    "msg":"success",
    "data": {}
}

API返回失败code错误码列表: | 错误码 | 错误详情 | | ---- | ---- | | 200000000 | 未获取到用户信息 | | 200000006 | 已订阅 | | 200000003 | 查询订阅号失败 | | 200000004 | 取消订阅失败 |

API使用示例:

/**
* 取消订阅
*
* @param {string} subscribeID 订阅id
* @param {string} openId 小程序openId
* @param {string} sourceFlag 订阅标识
*/

subscribeManager.cancelSub(subscribeID, openId, sourceFlag).then(res => {
    // res.code 为 0 时接口正常
    // 业务逻辑...
    if (!res.code) {
        swan.showToast({
            title: '取消成功',
            icon: 'none'
        });
    } else {
        swan.showToast({
            title: '取消失败',
            icon: 'none'
        });
    }
}).catch(err => {
    swan.showToast({
        title: '取消失败',
        icon: 'none'
    });
});

2.2.4 跳转订阅助手 toManage

API使用示例:

/**
 * 管理订阅,跳转到订阅助手小程序
 */
onSubscribeManage() {
    subscribeManager.toManage();
}

2.2.5 修改干预信息 modifyIntervene

API请求参数:

| 参数 | 类型 | 说明 | 是否必填 | | ---- | ---- | ---- | ---- | | subscribeID | String | 订阅id | 是| | openId | String | 小程序openId | 是 | | opType | Number | 1、新增标签(城市等)2、取消标签(城市等)3、修改标签(城市等) | 是 | | sourceFlag | String | 订阅标识 | 是 | | intervene | Array. | 修改城市列表 | 是 | | >> intervene[].type | Number | 特征类型 1(城市)2(省份)3(快递公司)4(运动员)| 是 | | >> intervene[].value | String | 用英文逗号把vaule值连接起来 | 是 |

API使用示例:

/**
 * 修改城市信息
 * @param {string} subscribeID 订阅id
 * @param {string} openId 小程序openId
 * @param {number} opType 1、新增干预城市 | 2、取消干预城市 | 3、修改干预城市
 * @param {string} sourceFlag 订阅标识
 * @param {string} intervene 修改城市列表
 * @return {Promise} 请求对象
 */
subscribeManager.modifyIntervene(subscribeID, openId, 1, sourceFlag, [
    {
        "type": 1, // type 1是城市
        "value": "130000,130001,130002"
    },
    {
        "type": 2, // type 2是省份
        "value": "130000,130003"
    }

]).then(res => {
    console.log(res)
});

API返回参数:

{
    "code": 0, // 为0时,操作成功
    "msg": "success",
    "data": {}
}

2.2.6 初始化订阅配置 subInit

API请求参数:

| 参数 | 类型 | 说明 | 是否必填 | | ---- | ---- | ---- | ---- | | conf | Object | 订阅配置信息 | 是| | >> conf.host | String | 订阅请求 HOST | 否|