# 基础
# createRequest
# Object createRequest(Object config)
创建网络请求对象,用于向腾讯出行服务平台后台发送网络请求
参数
- Object
config参数配置可选
| 字段名 | 类型 | 说明 | 默认值 | 是否可选 |
|---|---|---|---|---|
| withAuth | Boolean | 是否填充登录态参数 | - | 可选 |
| host | String | 自定义的host域名 | - | 可选 |
| baseParam | Object | 默认携带的参数 | - | 可选 |
返回值
| 类型 | 说明 |
|---|---|
| Object | Request实例 |
示例代码
const $ = getApp().tms.createRequest();
$.get(apiPath)
.then((resp) => {
// ...
})
.catch((err) => {
// ...
});
# getReporter
# Object getReporter()
创建埋点上报对象,用于向腾讯出行服务平台后台发送埋点
返回值
| 类型 | 说明 |
|---|---|
| Object | Reporter实例 |
示例代码
const $ = getApp().tms.getReporter();
/**
* 新埋点
* @param {string} 参数1 页面|组件的唯一标志
* @param {any} 参数2 埋点属性
* @param {any} 参数3 埋点属性
* @returns {void}
* @example
* reporter.report2('report_example_click', {}, {});
*/
$.report2('report_example_click', {}, {});
# md5
# String md5(String str)
基于md5算法对源字符串进行hash,生成hash字符串
参数
- String
str源字符串必填
返回值
| 类型 | 说明 |
|---|---|
| String | 源字符串的md5 hash值 |
# getOuterOpenId
# Promise<String> getOuterOpenId(String apiKey)
唯一标识 openId 用于服务接入方作为唯一标识、向腾讯出行服务同步订单等
服务接入
参数
- String
apiKey服务接入方渠道标识必填
返回值
| 类型 | 说明 |
|---|---|
| Promise<String> | 返回 openId,失败时返回空 |
# getEncryptUserInfo
# Promise<Object|String> getEncryptUserInfo(String mpId, String queryTypes)
获取用户加密信息
参数
- String
mpId服务接入方渠道标识必填 - String
queryTypes用户信息类型, 多种类型用,链接,eg: phone,nickname,headImgUrl必填
返回值
| 类型 | 说明 |
|---|---|
| Promise<Object|String> | 返回加密后的信息,失败返回errMsg |
示例
tms.getEncryptUserInfo('d4fe2f7c5bd541e69471', 'phone')
.then(res => {
// res === { encrStr: 'xxxx', seqId: 'xxx' }
})
.catch(e => {
// e === "错误原因"
});
# class:Request
网络请求类,对签名、鉴权等逻辑进行封装处理,用于向腾讯出行服务平台后台发送网络请求
# Promise Request.get(String path, Object param, Object header)
参数
String
path请求接口路径必填Object
param请求参数可选Object
header自定义请求头可选
返回值
| 类型 | 说明 |
|---|---|
| Promise | 接口响应 |
示例代码
const $ = getApp().tms.createRequest();
$.get(apiPath)
.then((data) => {
// data {Object} 响应数据
// {
// errCode {Number} 接口响应状态码
// errMsg {String} 接口响应状态信息
// resData {Object} 接口返回数据
// }
})
.catch((e) => {
// e {Object} 错误信息
});
# Promise Request.post(String path, Object param, Object header)
参数
String
path请求接口路径必填Object
param请求参数可选Object
header自定义请求头可选
返回值
| 类型 | 说明 |
|---|---|
| Promise | 接口响应 |
示例代码
const $ = getApp().tms.createRequest();
$.post(apiPath)
.then((data) => {
// data {Object} 响应数据
// {
// errCode {Number} 接口响应状态码
// errMsg {String} 接口响应状态信息
// resData {Object} 接口返回数据
// }
})
.catch((e) => {
// e {Object} 错误信息
});