记录一下,由于云函数需要请求获取json数据,本地接口请求不到,暂时解决不了,就找了线上返回的json数据测试。
物流接口—快递接口:
- http://www.kuaidi100.com/query?type=快递公司代号&postid=快递单号
快递公司编码:
- 申通=”shentong” EMS=”ems” 顺丰=”shunfeng” 圆通=”yuantong” 中通=”zhongtong” 韵达=”yunda” 天天=”tiantian” 汇通=”huitongkuaidi” 全峰=”quanfengkuaidi” 德邦=”debangwuliu” 宅急送=”zhaijisong”
例如:
- kuaidi100.com/query?type=shentong&postid=773307847812945
unipush-云函数-index.js
'use strict';
const uniPush = uniCloud.getPushManager({
appId: "__UNI__56C8C3E"
});
exports.main = async (event) => {
const url = 'http://www.kuaidi100.com/query?type=shentong&postid=773307847812946'; // 替换为有效的URL
try {
const res = await uniCloud.httpclient.request(url, {
method: "GET",
dataType: "json"
});
console.log("timingPushGetData--res");
console.log(res);
return await uniPush.sendMessage({
"push_clientid": "f9f4668b6ffe83e7f3b795849b8dc0ed",
"title": res.data.com+":"+res.data.nu,
"content": res.data.data[0].context, //content类型必须是string
"payload": {
"text": "体验一下uni-push2.0云函数,通过uniCloud.httpclient.request请求url获取数据"
},
"force_notification": true
});
} catch (error) {
console.error("请求数据失败:", error);
// 根据需要处理错误,比如返回一个错误对象给调用者
return { error: "请求数据失败", message: error.message };
}
};
使用NATAPP映射:
https://blog.csdn.net/weixin_44135807/article/details/104510621?spm=1001.2014.3001.5506