UNPKG

minif_node

Version:

各类平台的对接的一个sdk

513 lines (372 loc) 20.9 kB
# 微信 - 抖音对应业务 ## 前言 当前包打算是对接对应的各平台的api的集合方便开发者对该业务的使用,比如 [微信小程序](#wxmini) - [qq小程序](#qqmini) - 抖音小程序 - [抖音生活商家服务](#tik_tok) - 微信公众号 - 支付宝...... 当然我涉及到的业务我才去对接,当然你可以跟我们联系把你的api也对接上去方便自己维护和分享~ 现在已经对接的是: **抖音生活** - **微信小程序** 使用建议:建议用ts来对接,比较有很好的提示~ ## 使用说明(例子) ​ **yarn add minif_node(也可以npm)** ```javascript //建议 import {createtiktok ,tik_tok} from 'minif_node' //或者 const { createtiktok ,tik_tok} = require('minif_node'); let tiktok_live = createtiktok({ appid: "申请的appid", appSecret: "申请的appSecret", //可以不配置 | 不配置那么就本地缓存 redis_options: { ​ host: '127.0.0.1', ​ port: 6379, ​ password: '123456', ​ db: 0 } }) //当然你也可以 自己new 出来 比如 (但是不建议) let tiktok_live = new tik_tok({ appid: "申请的appid", appSecret: "申请的appSecret", //可以不配置 | 不配置那么就本地缓存 redis_options: { ​ host: '127.0.0.1', ​ port: 6379, ​ password: '123456', ​ db: 0 } }) //例子 获取自己的获取这次的请求的token信息 let getAccessTokenres = await tiktok_live.getAccessToken(); //就一行那你就得到你想要的 | 还有很多请去对应的文档中查看~ ``` ### <a id="wxmini">微信小程序(总览) </a> | api名称 | 函数名 | 描述 | | :----------------------------------------------------------: | :-----------------------------------------: | :--: | | 用户授权 | | | | [获取token](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getAccessToken.html) | [getAccessToken()](#wxminigetAccessToken) | | | [小程序登陆](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html) | [wxcodelogin()](#wxcodelogin) | | | 用户信息 | | | | [手机号验证](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html) | [getPhoneNumber()](#getPhoneNumber) | | | 小程序码/链接 | | | | [获取不限制的小程序码](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html) | [getUnlimitedQRCode()](#getUnlimitedQRCode) | | #### 开始 ```javascript import {createwxmini ,wxmini} from 'minif_node' let wx_mini_creat = createwxmini({ appid: "申请的appid", appSecret: "申请的appSecret", //可以不配置 | 不配置那么就本地缓存 redis_options: { ​ host: '127.0.0.1', ​ port: 6379, ​ password: '123456', ​ db: 0 } }) ``` #### <a id="wxminigetAccessToken">getAccessToken()</a> ```javascript const getAccessTokenres = await wx_mini_creat.getAccessToken() ``` #### <a id="wxcodelogin">wxcodelogin()</a> ```javascript //code是前端生成的code const wxcodeloginres = await wx_mini_creat.wxcodelogin(code:string) ``` #### <a id="getPhoneNumber">getPhoneNumber()</a> ```javascript //code是前端生成的验证的手机号的code const getPhoneNumberres = await wx_mini_creat.getPhoneNumber(code:string) ``` #### <a id="getUnlimitedQRCode">getUnlimitedQRCode()</a> ```javascript //code是前端生成的code const getUnlimitedQRCoderes = await wx_mini_creat.getUnlimitedQRCode({ // 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) scene: string, // 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置 page?: string, // 默认是true,检查page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);为 false 时允许小程序未发布或者 page 不存在, 但page 有数量上限(60000个)请勿滥用。 check_path?: boolean, // 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 env_version?: string, //默认430,二维码的宽度,单位 px,最小 280px,最大 1280px width?: number, //自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false auto_color?: boolean, // 默认是{"r":0,"g":0,"b":0} 。auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示 line_color?: unknown, // 默认是false,是否需要透明底色,为 true 时,生成透明底色的小程序 is_hyaline?: boolean, }) ``` ### <a id="qqmini">qq小程序(总览) </a> | api名称 | 函数名 | 描述 | | :----------------------------------------------------------: | :-------------------------------------------: | :--: | | 用户授权 | | | | [获取token](https://q.qq.com/wiki/develop/miniprogram/server/open_port/port_use.html#getaccesstoken) | [getAccessToken()](#qqminigetAccessToken) | | | [小程序登陆](https://q.qq.com/wiki/develop/miniprogram/server/open_port/port_login.html#code2session) | [qqcodelogin()](#qqcodelogin) | | | 二维码与链接 | | | | [生成二维码](#qqgetUnlimitedQRCode) | [getUnlimitedQRCode()](#qqgetUnlimitedQRCode) | | | | | | | | | | #### 开始 ```javascript import {createqqmini ,qqmini} from 'minif_node' let createqqmini = createqqmini({ appid: "申请的appid", appSecret: "申请的appSecret", //可以不配置 | 不配置那么就本地缓存 redis_options: { ​ host: '127.0.0.1', ​ port: 6379, ​ password: '123456', ​ db: 0 } }) ``` #### <a id="qqminigetAccessToken">getAccessToken()</a> ```javascript const getAccessTokenres = await createqqmini.getAccessToken() ``` #### <a id="qqcodelogin">qqcodelogin()</a> ```javascript //code是前端生成的 const qqcodeloginres = await wx_mini_creat.qqcodelogin(code:string) ``` #### <a id="qqgetUnlimitedQRCode">getUnlimitedQRCode()</a> ```javascript //扫码进入的小程序页面路径,小程序不填进入首页,小游戏无需填写 const getUnlimitedQRCoderes = await wx_mini_creat.getUnlimitedQRCode(path:string) ``` ### <a id="tik_tok">抖音生活商家服务(总览) </a> | api名称 | 函数名 | 描述 | | :----------------------------------------------------------: | :----------------------------------------------------------: | :-------------------------: | | 用户授权 | | | | [获取token](https://partner.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/client-token) | [getAccessToken()](#dylocagetAccessToken) | 获取token信息 | | 门店管理 | | | | [查询门店信息](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.shop/shop.query) | [get_poi_query()](#get_poi_query ) | 门店列表 | | 团队核销 | | | | [验券准备](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.fulfilment/certificate.prepare) | [check_ticket_start()](#check_ticket_start) | 注意:这里扫码和code是重叠的 | | [验券](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.fulfilment/certificate.verify) | [check_ticket_open()](#check_ticket_open ) | 验券数据 | | [撤销核销](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.fulfilment/certificate.cancel) | [check_ticket_cancel()](#check_ticket_cancel) | | | [券状态查询](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.fulfilment/certificate.get) | [check_ticket_certificateget()](#check_ticket_certificateget) | | | 团购对账 | | | | [验券历史查询](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.billing/certificate.verifyrecord.query) | [check_ticket_history_list()](#check_ticket_history_list) | | | [账单详细查询](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.billing/detailedquery) | [check_ticket_detailed_query()](#check_ticket_detailed_query) | | | [账单查询](#https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.billing/merchantquery) | [check_ticket_merchantquery()](#check_ticket_merchantquery) | | | [分账明细查询](#https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/life.capacity.billing/ledger.query-record-by-cert) | [query_record_by_cert()](#query_record_by_cert) | | | 订单查询 | | | | [查询订单](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/order.query/query) | [get_trade_order_query()](#get_trade_order_query) | | | 商品发布以及查询 | | | | [获取商品的数据](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/goods/draft.get) | [get_merchandise_online_data()](#get_merchandise_online_data) | | | [获取商品的数据列表](https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/goods/query) | [get_merchandise_online_data_list()](#get_merchandise_online_data_list) | | #### 开始 ```javascript import {createtiktok ,tik_tok} from 'minif_node' let tiktok_live = createtiktok({ appid: "申请的appid", appSecret: "申请的appSecret", //可以不配置 | 不配置那么就本地缓存 redis_options: { ​ host: '127.0.0.1', ​ port: 6379, ​ password: '123456', ​ db: 0 } }) ``` #### <a id="dylocagetAccessToken">getAccessToken()</a> ```javascript //得到自己的token const getAccessTokenres = await tiktok_live.getAccessToken() ``` #### <a id="get_poi_query">get_poi_query()</a> ```javascript const get_poi_queryres = await tiktok_live.get_poi_query({ page:1, // 页码 ,(从1开始) size: 20, // 一页大小 数值范围:[1, 100] account_id:'',//本地生活商家账户 ID(account_id和poi_id,二者必填其一,若都填写,account_id优先) poi_id: '', // 抖音门店 ID(account_id和poi_id,二者必填其一,若都填写,account_id优先) third_id:'', }) ``` #### <a id="check_ticket_start">check_ticket_start()</a> ```javascript const check_ticket_startres = await tiktok_live.check_ticket_start({ // 手输入的code code?: string, // 识别的短链的地址 short_chain?: string, }) ``` #### <a id="check_ticket_open">check_ticket_open()</a> ```javascript const check_ticket_openres = await tiktok_live.check_ticket_open({ // 一次验券的标识 在验券准备中获取~ verify_token: string, // 核销的抖音门店id poi_id: string, // 验券准备接口返回的加密抖音券码 encrypted_codes?: string[], // 三方原始券码值列表 (encrypted_codes/codes/code_with_time_list必须三选一) codes?: string[], // 抖音侧的订单号 (非预导码模式的三方券码必需) order_id?: string, // 带有核销时间的三方码列表 code_with_time_list?: string[], }) ``` #### <a id="check_ticket_cancel">check_ticket_cancel()</a> ```javascript const check_ticket_cancelres = await tiktok_live.check_ticket_cancel({ // 代表券码一次核销的唯一标识(验券时返回)(次卡撤销多次时请填0) verify_id: string, // 代表一张券码的标识(验券时返回) certificate_id: string, // 取消核销总次数(多次卡商品可传,优先级低于verify_id)注意:如果是分门店结算,此字段不要传!!! times_card_cancel_count?: number, // 撤销核销幂等操作,主要针对次卡,避免因超时等原因在短时间内重复请求导致撤销多次(幂等有效期1小时) 注意:如果是分门店结算,此字段不要传!!! cancel_token?: string, }) ``` #### <a id="check_ticket_certificateget">check_ticket_certificateget()</a> ```javascript const check_ticket_history_listres = await tiktok_live.check_ticket_certificateget({ // 页大小,取值范围20 size: number, // 游标,传前一页最后一条记录的游标(首页传0) cursor: string, //企业号商家总店id(验券准备接口中返回) account_id: string, //门店id列表,不传默认返回商家所有门店核销记录,多个值使用,拼接 poi_ids?: string[], //起始时间戳,单位秒,不传表示今天 start_time?: bigint, //截止时间戳,单位秒 end_time?: bigint }) ``` #### <a id="check_ticket_history_list">check_ticket_history_list()</a> ```javascript const check_ticket_history_listres = await tiktok_live.check_ticket_history_list({ // 页大小,取值范围20 size: number, // 游标,传前一页最后一条记录的游标(首页传0) cursor: string, //企业号商家总店id(验券准备接口中返回) account_id: string, //门店id列表,不传默认返回商家所有门店核销记录,多个值使用,拼接 poi_ids?: string[], //起始时间戳,单位秒,不传表示今天 start_time?: bigint, //截止时间戳,单位秒 end_time?: bigint }) ``` #### <a id="check_ticket_detailed_query">check_ticket_detailed_query()</a> ```javascript const check_ticket_detailed_queryres = await tiktok_live.check_ticket_detailed_query({ //商户id account_id: string, //查询游标,第一页查询传0,翻页查使用上一次查询返回cursor cursor: string, //页大小,取值范围1~50 size: number, // 核销日期,格式为"2006-01-02" bill_date: string, }) ``` #### <a id="check_ticket_merchantquery">check_ticket_merchantquery()</a> ```javascript const check_ticket_merchantqueryres = await tiktok_live.check_ticket_merchantquery({ //商户id account_id: string, //查询游标,第一页查询传0,翻页查使用上一次查询返回cursor cursor: string, //页大小,取值范围1~50 size: number, // 核销日期,格式为"2006-01-02" bill_date: string, }) ``` #### <a id="query_record_by_cert">query_record_by_cert()</a> ```javascript const get_trade_order_queryres = await tiktok_live.query_record_by_cert({ //券码的标识(验券时返回)列表,列表长度范围1~50,多个值使用拼接 certificate_ids: string[], }) ``` #### <a id="get_trade_order_query">get_trade_order_query()</a> ```javascript const get_trade_order_queryres = await tiktok_live.get_trade_order_query({ // 第几页(首页传1) page_num: number, // 页大小,取值范围1~100 page_size: number, // 商户id account_id: string, // 第三方订单号 ordequey?: string, // 第三方订单号 ext_order_id?: string, // 抖音用户id open_id?: string, // 订单状态 order_status?: number, // 创单起始时间 (秒时间戳,创单起止时间必须同时传入) create_order_start_time?: BigInt, // 创单结束时间(秒时间戳,创单起止时间必须同时传入) create_order_end_time?: BigInt, // 修改起始时间 (秒时间戳,修改起止时间必须同时传入 update_order_start_time?: BigInt, // 修改起始时间(秒时间戳,修改起止时间必须同时传入) update_order_end_time?: BigInt, // 是否查询用户隐私号 get_secret_number?: boolean, }) ``` #### <a id="get_merchandise_online_data">get_merchandise_online_data()</a> ```javascript const get_merchandise_online_datares = await tiktok_live.get_merchandise_online_data({ // 商品ID列表,多个值使用,拼接 product_ids?: string[], // 外部商品ID列表,多个值使用,拼接 out_ids?: string[], // 商家ID,传入时服务商须与该商家满足授权关系 account_id: string, }) ``` #### <a id="get_merchandise_online_data_list">get_merchandise_online_data_list()</a> ```javascript const get_merchandise_online_data_listres = await tiktok_live.get_merchandise_online_data_list({ // 第一页不传,之后用前一次返回的next_cursor传入进行翻页 cursor?: string, // 分页数量,不传默认为5,最大上限50 count?: number, // 过滤在线状态 1-在线 2-下线 3-封禁 status?: number, // 商家ID,传入时服务商须与该商家满足授权关系 account_id: string, // 区分商品创建者的查询方式 // 0 - 查询服务商/开发者创建的商品 // 1 - 查询商家(account_id)创建的商品 goods_creator_type?: number }) ``` ## 版本介绍 | 版本号 | 版本说明 | | :----: | :-------------------------------------------------------: | | v1.1.0 | 增加对应的分账明细的,以及其他部分调整基本上在原来上升级 | | v1.0.9 | 把记录redis的信息改为字符串 && 新增抖音小程序发的部分对接 | | v1.0.8 | qq小程序和微信小程序部分对接 | | v1.0.7 | 抖音生活部分对接完毕 | ## 联系 如果你看到这篇包如果有什么疑问或者有什么功能缺陷或者没有但是想要对接功能,可以联系我。 微信: ![](https://yqinyuan.top/userfileinterspace/4/material/wxsyyt2000.jpg) qq: ![](https://yqinyuan.top/userfileinterspace/4/material/qq178181502.jpg) ## 赞赏 ![](https://yqinyuan.top/userfileinterspace/4/material/zssyyt2000.jpg) ## 参与贡献 易沁沅