腾讯医典提供专业医疗科普百科、文章和视频的海量知识库,可通过搜索 API 接口查询相关内容。例如接口输入搜索“糖尿病如何治疗”,搜索 API 接口会返回糖尿病的疾病百科词条,还有涉及糖尿病治疗这个知识点的相关文章和视频列表,为用户解答糖尿病相关的疑问。
为了减少客户对接 API 的开发成本,医典提供一套标准的 H5 页面支持客户直接调用,客户无需自行开发搜索结果页的前端逻辑,直接跳转到医典的 H5 页面即可。H5搜索页面的计费模式仍然按照底层对应的 API 搜索次数来计费,每个客户单独一套密钥来生成动态 H5 链接。
动态 H5 链接对接说明
需要先生成签名,再用签名信息生成动态 H5链接.
签名生成说明
参数名称 | 参数代码 | 说明 |
当前 UNIX 时间戳 | timestamp | 单位秒。如果 timestamp 表示的时间戳与医典服务端时间相差超过三分钟,则认为请求过时,会拒绝请求并返回相应的错误。 |
随机数 | noncestr | 随机字符串,用于生成签名。 |
签名 | signature | 生成签名的流程如下: 1. appid,timestamp,noncestr三个参数按"appid=%s&noncestr=%s×tamp=%s" 格式拼接。 2. 使用 appserect 将上述拼接字符串通过 hmac 签名算法进行 sha256 摘要(直接 hmac 时 sha256),编码为字符串后即为此次请求的签名。 |
渠道 ID | appid | |
渠道密钥 | appserect | |
渠道标识 | adtag |
生成 H5 动态链接
动态 H5 链接需使用如下参数进行拼接:
search(即搜索词,例如高血压;可以留空)、 adtag、appid、noncestr、signature、timestamp
预发布环境域名-开发测试用:
https://preview.baike.qq.com/mobile/search_business.html?search=query&adtag=XXX&appid=XXX&noncestr=XXX×tamp=XXX&signature=XXX
生产环境域名-正式上线链接:
https://h5.baike.qq.com/mobile/search_business.html?search=query&adtag=XXX&appid=XXX&noncestr=XXX×tamp=XXX&signature=XXX
说明:
在开发联调测试时,请使用预发布环境的域名;上线后使用正式环境域名。
代码示例
1. 安装 crypto-js,并引入
npm i crypto-js --saveimport CryptoJSEncHex from 'crypto-js/enc-hex';import hmacSHA256 from 'crypto-js/hmac-sha256';
2. 对参数加密生成 url
generateUrl() {const signature = this.getSignature();const params = {adtag: this.adtag,appid: this.appid,search: this.searchWord,...signature,};// 参数拼接生成urlthis.url = `xxx.html?adtag=${params.adtag}&appid=${params.appid}&search=${params.search}×tamp=${params.timestamp}&noncestr=${params.noncestr}&signature=${params.signature}`;},getHmacSHA256(str, key) {return hmacSHA256(str, key).toString(CryptoJSEncHex); // 搜索商业化接口参数加密},getSignature() {const t = +new Date();const timestamp = `${Math.floor(t / 1000)}`; // 客户服务器实时时间戳,与北京时间相差不能超过3分钟const noncestr = 'test'; // 客户自定义随机数,长度在32位以内const { appid } = this; // 客户的appidconst appserect = 'xxxxxx'; // 密钥// 传入拼接参数和密钥const signature = this.getHmacSHA256(`appid=${appid}&noncestr=${noncestr}×tamp=${timestamp}`, appserect);return {timestamp,noncestr,appid,signature,};},
小程序校验文件
如果是小程序内嵌医典的 H5 页面,由于微信平台要求域名需授权才能访问,否则无法打开您备案域名以外的第三方域名,所以需客户提供校验文件给医典侧配置,具体流程如下: