没有合适的资源?快使用搜索试试~ 我知道了~
php接口api从服务端到客户端教程[参照].pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 198 浏览量
2021-10-11
23:35:17
上传
评论
收藏 235KB PDF 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/31569349/0001-4ea04ec7feb8ef6291bc11c48431b012_thumbnail.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
43页
php接口api从服务端到客户端教程[参照].pdf
资源推荐
资源详情
资源评论
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![synapse3](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://csdnimg.cn/release/download_crawler_static/31569349/bg1.jpg)
<?php
/*************************************************
5PK API 框架设计
ClientApi.php 页面 把变量 post 到 service.php 页面中
//简单的客户端调用服务端 serviceapi 接口的示例
/*
* 例 如 客 服 端 通 过 网 址 这 样 传 值
http://www.szduomei_lvlaotou.com/api.php?key=123456&num=88888&show=1
*key 由系统分发的 key
*num 要查询的 然后通过该数据返回值
*show 返回的数据 例如 :1 为 josn,2 为 xml,3 为 html 等
*/
/*************************************************/
//客户端调用 API 测试
$url = 'http://localhost/api/ServeiceAPI.php' ;
$key=2008214209; // 需要 post 到 ok.php 页面的变量
$num="laoma";
$show=1;
$fields = array( // 把所有变量进行数组化保存到数组 fields 中
'key'=>urlencode($key) ,
'num'=>urlencode($num) ,
'show'=>urlencode($show) ,
);
foreach($fields as $key=>$value)
{
$fields_string .= $key.'='.$value.'&' ;// 把 变 量 组 装 成
username=mayuchao&password=123456& 成功了 mayuchao 密码 laoma 这个格式
}
![](https://csdnimg.cn/release/download_crawler_static/31569349/bg2.jpg)
rtrim($fields_string ,'&') ; // 从末端开始去掉删除多余 & 符号
$ch = curl_init() ; // 开启一个 curl 对话
curl_setopt($ch, CURLOPT_URL,$url) ; // 把要对话的 url 地址设置好
curl_setopt($ch, CURLOPT_POST,count($fields)) ; // 把要发送的变量数量设置好
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ; // 把要 post 的变量 url 组装好化后设
置好
curl_exec($ch) ; // 执行上面设置好的一个 curl 操作,把变量数据发送完后,返回的是 ok.php
页面获得 post 变量执行后的结果
curl_close($ch) ; // 关闭 curl 对话
?>
<?php
//简单的服务端提供 api 示例
/*
* 例 如 通 过 网 址 这 样 传 值
http://www.szduomei_lvlaotou.com/api.php?key=123456&num=88888&show=1
*key 由系统分发的 key
*num 要查询的 然后通过该数据返回值
*show 返回的数据 例如 :1 为 josn,2 为 xml,3 为 html 等
*/
$key = $_POST['key']; // 获取传来的变量 key
$num = $_POST['num'];// 获取传来的变量 knum
$show = $_POST['show']; // 获取传来的变量 show
function checkkey($key,$show)
{
![](https://csdnimg.cn/release/download_crawler_static/31569349/bg3.jpg)
if($key==2008214209)
{
return get_data($num);
}
else
{
if($show==1)
{
return 'josn 数据 ';
}
else if($show==2)
{
return 'xml';
}
else
{
return ' 默认的格式 ';
}
}
}
if(!empty($key)) // 简单验证 key
{
![](https://csdnimg.cn/release/download_crawler_static/31569349/bg4.jpg)
checkkey($key,$show);
}
//检查 key 的有效性
//返回通过 url 过来的值查找对应的数据
function get_data($num){
if($show==1)
{
return 'josn 数据 ';
}
else if($show==2)
{
return 'xml';
}
else
{
return ' 默认的格式 ';
}
}
echo $key;
?>
<?php
class TopClient
{
public $appkey;
![](https://csdnimg.cn/release/download_crawler_static/31569349/bg5.jpg)
public $secretKey;
public $gatewayUrl = "http://gw.api.taobao.com/router/rest";
public $format = "xml";
/** 是否打开入参 check**/
public $checkRequest = true;
protected $signMethod = "md5";
protected $apiVersion = "2.0";
protected $sdkVersion = "top-sdk-php-20110909";
protected function generateSign($params)
{
ksort($params);
$stringToBeSigned = $this->secretKey;
foreach ($params as $k => $v)
{
if("@" != substr($v, 0, 1))
{
$stringToBeSigned .= "$k$v";
}
}
unset($k, $v);
$stringToBeSigned .= $this->secretKey;
return strtoupper(md5($stringToBeSigned));
}
protected function curl($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (is_array($postFields) && 0 < count($postFields))
{
$postBodyString = "";
剩余42页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
czq131452007
- 粉丝: 2
- 资源: 12万+
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
下载权益
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
C知道特权
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
VIP文章
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
课程特权
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)