From 7445094c33ebf3ca8321abc7b68b4f64c69d3d31 Mon Sep 17 00:00:00 2001 From: qinzongqing Date: Fri, 14 Apr 2023 15:52:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E5=BC=80=E5=8F=91=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/Oauth2Controller.php | 6 +-- app/controllers/SmsController.php | 66 ++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/app/controllers/Oauth2Controller.php b/app/controllers/Oauth2Controller.php index b358310..777bd73 100644 --- a/app/controllers/Oauth2Controller.php +++ b/app/controllers/Oauth2Controller.php @@ -17,14 +17,14 @@ class Oauth2Controller extends ControllerBase{ * http://weapp.wemediacn.net/d/tiffany/api/oauth2/test?qaz=wsx */ function testAction(){ - //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/code"; + $url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/code"; //$url = "http://127.0.0.1/tiffany/api/oauth2/code?qaz=wsx"; //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/accesstoken"; - $url = "http://127.0.0.1/tiffany/api/oauth2/accesstoken?qaz=wsx"; + //$url = "http://127.0.0.1/tiffany/api/oauth2/accesstoken?qaz=wsx"; $post_arr = array(); $post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7"; $post_arr['appsecrect'] = "b82015bd-8d4c-4df8-87a8-c25477a8976f"; - $post_arr['code'] = "4w6cuxof5gvhi9szpeabj32l71mqrtd8"; + $post_arr['code'] = "c21ffda53bb349ff9461c92e4371da93"; $post_json = json_encode($post_arr); $result = $this->__http_post_request($url, $post_json, true); print_r($result); die; diff --git a/app/controllers/SmsController.php b/app/controllers/SmsController.php index db383f4..066cb0d 100644 --- a/app/controllers/SmsController.php +++ b/app/controllers/SmsController.php @@ -38,9 +38,9 @@ class SmsController extends ControllerBase{ //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/sms/send"; //$url = "http://127.0.0.1/tiffany/api/sms/send?qaz=wsx"; //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/sms/authcode"; - $url = "http://127.0.0.1/tiffany/api/sms/authcode?qaz=wsx"; + //$url = "http://127.0.0.1/tiffany/api/sms/authcode?qaz=wsx"; //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/sms/query_reports"; - //$url = "http://127.0.0.1/tiffany/api/sms/query_reports?qaz=wsx"; + $url = "http://127.0.0.1/tiffany/api/sms/query_reports?qaz=wsx"; $post_arr = array(); $post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7"; $post_arr['mobile'] = "13501882318"; @@ -56,7 +56,10 @@ class SmsController extends ControllerBase{ $post_arr['params5'] = 5; $post_arr['params6'] = 6; $post_arr['is_resend'] = true; - $post_arr['min_id'] = ""; + $post_arr['min_id'] = 4115398953; + $post_arr['min_id'] = 4116344287; + $post_arr['min_id'] = 4116344229; + $post_arr['min_id'] = 0; $post_json = json_encode($post_arr); $result = $this->__http_post_request($url, $post_json, true); print_r($result); die; @@ -796,7 +799,62 @@ class SmsController extends ControllerBase{ } //如果以上判断都通过 if(empty($rs['errcode'])){ - + //设置查询MinID + $MinID = isset($request_arr['min_id'])?$request_arr['min_id']:0; + $MinID = (int)$MinID; + //设置查询TokenID + $TokenID = $AppInfo->SmsToken; + //开发阶段转为使用测试TokenID + $TokenID = "7100477830459267"; + //准备查询下行报告 + $url = "https://www.wemediacn.net/webservice/smsservice.asmx/QuerySmsSeqReport?TokenID=$TokenID&MinID=$MinID"; + //获取查询结果 + $xml = $this->__https_request($url); + //转换查询结果格式 + $array = $this->__change_xml_to_array($xml); + //获取查询结果提示 + $string = !empty($array[0])?$array[0]:""; + //如果查询失败 + if(!isset($array['@attributes'])){ + //告知用户"系统繁忙,请稍候再试" + $rs['errcode'] = -1; + $rs['errmsg'] = "系统繁忙,请稍候再试"; + $rs['data'] = null; + } + //如果查询成功 + else{ + //告知用户"ok" + //注意: + //原代码逻辑中有多返回一个@count,而文档中则没有写到 + //此处先遵循原代码逻辑,而不按照文档中所写的不做返回 + $rs['errmsg'] = "ok"; + $rs['errcode'] = 0; + $rs['data']['NewDataSet']['@nextID'] = $array['@attributes']['nextID']; + $rs['data']['NewDataSet']['@count'] = $array['@attributes']['count']; + $rs['data']['NewDataSet']['@xmlns'] = ""; + //如果无新下行报告 + if(empty($array['result'])){ + //设置返回结果 + $rs['data']['NewDataSet']['result'] = array(); + } + //如果有新下行报告 + else{ + //如果有新下行报告,但只有一条 + if($array['@attributes']['count']==1){ + //转换为多维数组 + $array['result'] = array(0=>$array['result']); + } + //循环新下行报告 + foreach($array['result'] as $result){ + //转换查询结果 + $result['org_messageid'] = $result['org_messageid']!=array()?$result['org_messageid'][0]:null; + $result['ip'] = $result['ip']!=array()?$result['ip'][0]:null; + //设置返回结果 + $rs['data']['NewDataSet']['result'][] = $result; + } + } + + } } } }