线上获取json数据进行测试

记录一下,由于云函数需要请求获取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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值