From 0fa3305acd8fab046acbeb82ca6a0d107fee0467 Mon Sep 17 00:00:00 2001 From: qinzongqing Date: Mon, 10 Apr 2023 12:49:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ControllerBase.php | 33 ++++++++++++++++--------- app/controllers/Oauth2Controller.php | 15 ++++++++++- app/models/Smsapioauth2Accesstoken.php | 12 +++++++++ app/models/Smsapioauth2Appinfo.php | 12 +++++++++ app/models/Smsapioauth2Refreshtoken.php | 12 +++++++++ app/models/Smsapioauth2Tempcode.php | 12 +++++++++ 6 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 app/models/Smsapioauth2Accesstoken.php create mode 100644 app/models/Smsapioauth2Appinfo.php create mode 100644 app/models/Smsapioauth2Refreshtoken.php create mode 100644 app/models/Smsapioauth2Tempcode.php diff --git a/app/controllers/ControllerBase.php b/app/controllers/ControllerBase.php index 2003238..b74ac34 100644 --- a/app/controllers/ControllerBase.php +++ b/app/controllers/ControllerBase.php @@ -35,26 +35,37 @@ class ControllerBase extends Phalcon\Mvc\Controller{ curl_close($curl); return $data; } - + /** * curl post */ - function __http_post_request($url, $postArr){ + function __http_post_request($url, $data=null, $is_json=false){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); - //curl_setopt ( $curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); - curl_setopt($curl, CURLOPT_SSLVERSION, 1); - curl_setopt($curl, CURLOPT_TIMEOUT, 60); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0); - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postArr); + if(!empty($data)){ + if($is_json && is_array($data)){ + $data = json_encode($data); + } + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + //发送JSON数据 + if($is_json){ + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length:'.strlen($data))); + } + } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - $data = curl_exec($curl); + $res = curl_exec($curl); + $errorno = curl_errno($curl); + if($errorno){ + $error = array(); + $error = array('errorno'=>false, 'errmsg'=>$errorno, 'msg'=>curl_error($curl), 'info'=>curl_getinfo($curl)); + return $error; + } curl_close($curl); - return $data; + return $res; } /** diff --git a/app/controllers/Oauth2Controller.php b/app/controllers/Oauth2Controller.php index 1872da0..3fa7914 100644 --- a/app/controllers/Oauth2Controller.php +++ b/app/controllers/Oauth2Controller.php @@ -11,12 +11,25 @@ class Oauth2Controller extends ControllerBase{ parent::initialize(); } + /** + * 测试方法 + * http://127.0.0.1/tiffany/api/oauth2/test?qaz=wsx + */ + function testAction(){ + $url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/code"; + $post_arr = array(); + $post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7"; + $post_json = json_encode($post_arr); + $result = $this->__http_post_request($url, $post_json, true); + print_r($result); die; + } + /** * 获取code(Get code) * http://127.0.0.1/tiffany/api/oauth2/code?qaz=wsx */ function codeAction(){ - + echo "111"; die; } /** diff --git a/app/models/Smsapioauth2Accesstoken.php b/app/models/Smsapioauth2Accesstoken.php new file mode 100644 index 0000000..0119720 --- /dev/null +++ b/app/models/Smsapioauth2Accesstoken.php @@ -0,0 +1,12 @@ +setSource("smsapioauth2_accesstoken"); + } + +} \ No newline at end of file diff --git a/app/models/Smsapioauth2Appinfo.php b/app/models/Smsapioauth2Appinfo.php new file mode 100644 index 0000000..c8935b4 --- /dev/null +++ b/app/models/Smsapioauth2Appinfo.php @@ -0,0 +1,12 @@ +setSource("smsapioauth2_appinfo"); + } + +} \ No newline at end of file diff --git a/app/models/Smsapioauth2Refreshtoken.php b/app/models/Smsapioauth2Refreshtoken.php new file mode 100644 index 0000000..f767f7f --- /dev/null +++ b/app/models/Smsapioauth2Refreshtoken.php @@ -0,0 +1,12 @@ +setSource("smsapioauth2_refreshtoken"); + } + +} \ No newline at end of file diff --git a/app/models/Smsapioauth2Tempcode.php b/app/models/Smsapioauth2Tempcode.php new file mode 100644 index 0000000..b0481e0 --- /dev/null +++ b/app/models/Smsapioauth2Tempcode.php @@ -0,0 +1,12 @@ +setSource("smsapioauth2_tempcode"); + } + +} \ No newline at end of file