diff --git a/app/controllers/Oauth2Controller.php b/app/controllers/Oauth2Controller.php index 4b6c040..80281e1 100644 --- a/app/controllers/Oauth2Controller.php +++ b/app/controllers/Oauth2Controller.php @@ -19,12 +19,12 @@ class Oauth2Controller extends ControllerBase{ function testAction(){ //$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://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/accesstoken"; + $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'] = "e985c2245a7445cb8487d9a4dd4d1c2a"; + $post_arr['code'] = "ua0mqjhsbdp8i4xt5ekwg2zn1693yc7f"; $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 0b6f58c..bb39c30 100644 --- a/app/controllers/SmsController.php +++ b/app/controllers/SmsController.php @@ -17,13 +17,13 @@ class SmsController extends ControllerBase{ * http://weapp.wemediacn.net/d/tiffany/api/sms/test?qaz=wsx */ function testAction(){ - $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/send"; + $url = "http://127.0.0.1/tiffany/api/sms/send?qaz=wsx"; $post_arr = array(); - $post_arr['appid'] = "4fb8f3fa-30b4-4814-86d5-f2ea36a9b62a"; - $post_arr['access_token'] = "be4f6d1d08af434f933b1bbf6dbc02d2"; - $post_arr['mobile'] = "999"; - $post_arr['content'] = "test"; + $post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7"; + $post_arr['access_token'] = "rozety97524isvwlj013npbcga8xhfqm"; + $post_arr['mobile'] = "13501882318"; + $post_arr['content'] = rand(1000, 9999); $post_arr['format'] = "555"; $post_json = json_encode($post_arr); $result = $this->__http_post_request($url, $post_json, true); @@ -201,8 +201,42 @@ class SmsController extends ControllerBase{ } //如果以上判断都通过 if(empty($rs['errcode'])){ - //{"errmsg":"发送失败,err detail:短信发送失败:ERROR:200:[非手机号码]","errcode":70000,"data":null} - //{"errmsg":"发送失败,err detail:短信发送失败:ERROR:108:[FormatID 非法数值]","errcode":70000,"data":null} + //设置手机号 + $mobile = $request_arr['mobile']; + //设置FormatID + $FormatID = !empty($request_arr['format'])?$request_arr['format']:8; + //设置内容 + $Content = urlencode($request_arr['content']); + //设置TokenID + //$TokenID = $AppInfo->SmsToken; + $TokenID = "7100477830459267"; + //准备发送短信 + $url = "http://www.wemediacn.net/webservice/smsservice.asmx/SendSMS?mobile=$mobile&FormatID=$FormatID&Content=$Content&ScheduleDate=2010-1-1&TokenID=$TokenID"; + //获取发送结果 + $xml = $this->__https_request($url); + //转换发送结果格式 + $array = $this->__change_xml_to_array($xml); + //获取发送结果提示 + $string = !empty($array[0])?$array[0]:""; + //如果发送失败 + if(!(strpos(strtolower($xml), "ok")!==false)){ + //告知用户发送失败,err detail:短信发送失败: + //ERROR:200:[非手机号码] + //ERROR:108:[FormatID 非法数值] + $rs['errmsg'] = "发送失败,err detail:短信发送失败:".$string; + $rs['errcode'] = 70000; + $rs['data'] = null; + } + //如果发送成功 + else{ + //获取messageid + //OK:[202304121675878871004778] + $messageid = str_replace("]", "", str_replace("OK:[", "", $string)); + //告知用户ok + $rs['errmsg'] = "ok"; + $rs['errcode'] = 0; + $rs['data']['messageid'] = $messageid; + } } } }