curl页面:

<?php

namespace frontend\controllers;
use yii\base\Controller;
use Yii;
class NewController extends Controller{ public $result=array(
'code'=>0,
'data'=>'',
'error'=>''
);
public function actionIndex(){
$user=Yii::$app->request->get('user');//获取用户名
$pwd=Yii::$app->request->get('pwd');//获取密码
$token=file_get_contents('./user.txt');//生成token
if(empty($user)){
return 1004;
}
if(empty($pwd)){
return 1005;
}
$url='http://www.xyii.com/v1/new/login';//登录接口地址
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
 curl_setopt($ch, CURLOPT_USERPWD, 'username' . ":" . 'password');//出现身份认证问题时加入
    curl_setopt($ch,CURLOPT_HEADER,FALSE);
curl_setopt($ch,CURLOPT_POSTFIELDS,array('user'=>$user,'pwd'=>$pwd,'token'=>$token));
$data=curl_exec($ch);
curl_close($ch);
$data=json_decode($data);
$this->result['data']=$data;
return json_encode($this->result);
}
}
//登录接口 控制器层
$user=Yii::$app->request->post('user');
$pwd=Yii::$app->request->post('pwd');
$id=Yii::$app->request->post('id');
$token=Yii::$app->request->post('token');
if($id<1){
return 1000;
}
if(empty($user)){
return 1001;
}
if(empty($pwd)){
return 1002;
}
if(empty($token)){
return 1003;
}
$params=array(
'user'=>$user,
'pwd'=>$pwd
);
$rows=User::getOne($id);
$this->result['data']=$rows;
return $this->result;
//模型层
public static $_tbl='user';
public static function getOne($id){
$db=Yii::$app->db->createCommand("SELECT `id`,`user`,`pwd` FROM".self::$_tbl);
$query=$db->bindValue('id',$id)->queryOne();
if(is_array($query)){
return $query;
}
return array();
}

CURL 调用登录接口并且携带Token的更多相关文章

  1. Python接口测试中通过登录接口获取实时token

    1.封装login_token 2.headers:对应登录请求头部信息 3.request_param:登录的参数数据 4.json.dumps:将一个Python数据结构转换为JSON 5.dic ...

  2. Python+request 登录接口reponse中token传递给其他接口使用,小示例介绍《一》

    要求: 1.调用登录login 2.调用通过登录接口返回的reponse中的token和uuid,实现test_create_todo接口的测试 实现: 1.login登录接口的调用,直接填写对应的U ...

  3. Yii2通过curl调用json-rpc接口

    Yii2可以通过json-rpc为前端提供接口数据,通常情况睛会使用异步的形式调用接口,有时也会使用curl调用接口数据. 一.异步调用json-rpc接口 $.ajax({ type: 'POST' ...

  4. php通过curl调用jpush接口实现消息的推送

    public function actionNotifyto() { //$regid = $_REQUEST['regid']; $url = 'https://api.jpush.cn/v3/pu ...

  5. 用curl调用https接口

    今天在windows下用curl类获取微信token一直返回false,查阅资料后,发现是https证书的锅,在curl类中加上这两条,问题瞬间解决. curl_setopt($ch, CURLOPT ...

  6. python+pytest接口自动化(13)-token关联登录

    在PC端登录公司的后台管理系统或在手机上登录某个APP时,经常会发现登录成功后,返回参数中会包含token,它的值为一段较长的字符串,而后续去请求的请求头中都需要带上这个token作为参数,否则就提示 ...

  7. Spring Boot web API接口设计之token、timestamp、sign

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/vbirdbest/article/details/80789817一:token 简介Token:访 ...

  8. Java生鲜电商平台-API接口设计之token、timestamp、sign 具体设计与实现

    转载:https://www.cnblogs.com/jurendage/p/12653865.html 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安 ...

  9. Java生鲜电商平台-API接口设计之token、timestamp、sign 具体架构与实现(APP/小程序,传输安全)

    Java生鲜电商平台-API接口设计之token.timestamp.sign 具体设计与实现 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安全呢(防窃 ...

随机推荐

  1. 002-红黑树【B-树】、二叉查找树

    一.引述-二叉查找树 红黑树(Red Black Tree) 一种特殊的二叉查找树.故先查看二叉查找树 二叉查找树特性:左字数上所有的节点的值都小于或等于他的根节点上的值 右子树上所有节点的值均大于或 ...

  2. spring datasource 使用 proxool

    XmlWebApplicationContext使用的xml配置如下: <?xml version="1.0" encoding="UTF-8"?> ...

  3. eclipse出现An internal error occurred during: "Building workspace". Java heap space 错误

    出现这个错误,eclipse 会卡死,以及自动退出 解决方案 工程根目录 找到项目中.project文件 删除这两处 第一处: <buildCommand> <name>org ...

  4. Intellij Idea debug 模式如果发现异常,即添加异常断点在发生异常处

    以前用eclipse的时候,可以根据所抛出的异常进行调试,比如:出现了空指针异常,我想知道是哪一行抛出的,在eclipse中我只需在debug模式下把空指针异常这个名字设置进去,当遇到空指针异常时,e ...

  5. 快学Scala 第6章 对象 - 练习

    1. 编写一个Conversions对象,加入inchesToCentimeters.gallonsToLiters和milesToKilometers方法. object Conversions { ...

  6. node获取windows pc 机器的标示

    var exec = require('child_process').exec; if(process.platform != "win32"){ //window throw ...

  7. sitecore开发入门之Sitecore字典结构最佳实践

    使用Sitecore时,一个重要的主题是如何为您的网站处理不同的语言和区域.Sitecore对此的回答是使用字典项,它基本上只代表键/值定义.但是,这个字典项可以设置为具有不同的语言版本,这几乎允许您 ...

  8. ArrayList 除重

    看到一段简洁的 ArrayList 除重代码: protected final <T> List<T> removeDuplicates(List<T> list) ...

  9. JavaScript判断对象有没有定义

    if ( typeof(callbackfun) != "undefined" ) { callbackfun(); }

  10. ARM-ili9325屏调试1--时序

    2011-06-21 22:04:54 LCD连接好了,读id,不成功.说明配置引脚或读写时序不对. 原来是软件引脚配置出错. 应该用如下. #define LCD_CS   {3<<30 ...