首先你需要使用对方约定方式获取,然后考虑是否使用缓存,最后获取到数据后使用json_decode函数解析成数组格式,此时此刻呢就是自己的逻辑代码了.
一般使用php发送请求,获取返回的数据,进行解析;
php
$url="接口地址";
//发送请求获取返回值,file_get_contents只支持get请求,post使用curl
$json = file_get_contents($url);
//把json数据转化成数组
$data = json_decode($json,true);
//打印看看
print_r($data);
wx.request({
url: '',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
data: { mobile: e.detail.value.mobile, password: e.detail.value.password },
success: function (res) {
if (res.data.status == 0) {
wx.showToast({
title: res.data.info,
icon: 'loading',
})
} else {
title: res.data.info,//这里打印出登录成功
icon: 'success',
duration: 1000
}
fail: function () {
title: '服务器网络错误!',
PHP可以使用函数:file_get_contents函数获取外部json数据接口的数据,得到这些数据以后php再转成数组或对象传给前台html页面显示即可.
以上就是土嘎嘎小编为大家整理的php拿到接口数据相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!