1.通过Model调用

<?php
/**
* 积分模型 api接口
*/
class ApiModel{
private $url = 'http://js.yunlutong.com/Customer/Interface'; public function test() {
$post_data['action'] = 'sadf';
$post_data['callback'] = '?';
$res = request_post($this->url, $post_data);
$firstChar = substr($res,0,1);
if ($firstChar =='?') {
$res = substr($res,2);
$res = substr($res,0,strlen($res)-1);
} elseif($firstChar == '(') {
$res = substr($res,1);
$res = substr($res,0,strlen($res)-1);
}
dump(json_decode($res,true));
}
}

没有继承Model,否则会因为表不存在而报错。

调用,

$Api = D('Api');
$Api->test();

调用确实方便,但是总感觉有点不合理。这个D毕竟是操作数据库的。

2.通过引入类实现,把类放到ORG下

<?php
class Integral{
private $url = 'http://js.yunlutong.com/Customer/Interface'; public function test() {
$post_data['action'] = 'sadf';
$post_data['callback'] = '?';
$res = request_post($this->url, $post_data);
$firstChar = substr($res,0,1);
if ($firstChar =='?') {
$res = substr($res,2);
$res = substr($res,0,strlen($res)-1);
} elseif($firstChar == '(') {
$res = substr($res,1);
$res = substr($res,0,strlen($res)-1);
}
dump($res);
dump(json_decode($res,true));
} }
?>

调用

import("@.ORG.Api.Integral");
$integralApi = new Integral();
$integralApi->test();

配置一下,自动加载

'APP_AUTOLOAD_PATH'     => '@.ORG,@.ORG.Api',

这样调用就方便了不管Api文件夹下有多少类,都会自动加载,不需要单个引用import("@.ORG.Api.Integral")了。

最新文章

  1. DELPHI实现关闭指定进程,自身防杀
  2. Spark:读取hdfs gz压缩包
  3. Spring透过ApplicationListener来触发contextrefreshedevent事件
  4. 如何查看mac系统是32位还是64位的操作系统
  5. C字符串和C++中string的区别 &amp;&amp;&amp;&amp;C++中int型与string型互相转换
  6. centos nginx和tomcat 通过反向代理生成想要的nexus网址
  7. Linux kernel ‘aac_send_raw_srb’函数输入验证漏洞
  8. Linux OpenCV读取视频失败,cvCreateFileCapture失败的解决
  9. JavaScript详解
  10. python爬虫入门(八)Scrapy框架之CrawlSpider类
  11. MySql 8.0 C#连接报错 MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host &#39;12.118.224.181&#39; for user &#39;root&#39; using method &#39;caching_sha2_password&#39; failed with message: Reading from t
  12. 使用OClint进行iOS项目的静态代码扫描
  13. boost asio 一个聊天的基本框架
  14. 在SpringTest中将Mockito的mock对象通过spring注入使用
  15. FFT(快速傅里叶变换)算法详解
  16. just_sort
  17. windows10下如何进行源码编译安装tensorflow
  18. 分享 - 普通程序员如何转向AI方向
  19. ted飞行器
  20. JAVA变量的执行顺序

热门文章

  1. php变量简单介绍
  2. 报错org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in class path resource [bean.xml]
  3. 用 LoadLibraryExW 函数测试加载 dll (CSharp、Windows)
  4. Linux 下硬链接和软链接的说明
  5. MongoCola使用教程 2 - MongoDB的Replset 初始化和配置
  6. 再论typedef
  7. 记录下httpclient 发送请求 服务端用@RequestBody 自动接收参数 报415
  8. Android中轻松使用线程
  9. .Net 中的IL中间语言基本语法
  10. Linux下shell命令 1