{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
以上是通过https访问可得到的 json
<?php
$url = 'https://jsonplaceholder.typicode.com/posts/1';//网络url
$json = file_get_contents($url);
$jo = json_decode($json);
echo $jo->title;
?>
php执行,页面输出:sunt aut facere repellat provident occaecati excepturi optio reprehenderit
注:如file_get_contents失效,需配置php.ini
allow_url_fopen 是on
allow_url_include 是on
url是https,php.ini还需以下配置
extension=php_openssl.dll 果断开启
附php得到微信小程序openid
$appid='wxf0426d84f*******';//小程序appid
$secret='e0bc99163**************8';//小程序秘钥
$code=$_GET['code'];//uniapp模拟登录前台自动获得
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$appid.'&secret='.$secret.'&js_code='.$code.'&grant_type=authorization_code';
$json = file_get_contents($url);
$jo = json_decode($json);
//echo $jo->openid;
$openid = $jo->openid;