Heim > php教程 > php手册 > ThinkPhp调用webservice,thinkphpwebservice

ThinkPhp调用webservice,thinkphpwebservice

WBOY
Freigeben: 2016-06-13 09:18:29
Original
2408 Leute haben es durchsucht

ThinkPhp调用webservice,thinkphpwebservice

模板页:

<span> 1</span> <span><!</span><span>DOCTYPE html</span><span>></span>
<span> 2</span> <span><</span><span>html</span><span>></span>
<span> 3</span> <span><</span><span>head</span><span>></span>
<span> 4</span> <span><</span><span>meta </span><span>charset</span><span>="UTF-8"</span><span>></span>
<span> 5</span> <span><</span><span>title</span><span>></span>Insert title here<span></</span><span>title</span><span>></span>
<span> 6</span> <span><</span><span>script </span><span>type</span><span>="text/javascript"</span><span> src</span><span>="../Public/jquery-1.8.0.min.js"</span><span>></</span><span>script</span><span>></span>
<span> 7</span> <span><</span><span>script </span><span>type</span><span>="text/javascript"</span><span>></span>
<span> 8</span> <span>    $(</span><span>function</span><span>() {
</span><span> 9</span>         <span>var</span><span> OCXobj </span><span>=</span><span> document.getElementById(</span><span>"</span><span>PlayViewOCX</span><span>"</span><span>);
</span><span>10</span> <span>        OCXobj.SetOcxMode(</span><span>0</span><span>);
</span><span>11</span> <span>        $.ajax({
</span><span>12</span>             <span>//</span><span>要用post方式   </span>
<span>13</span> <span>            type : </span><span>"</span><span>Post</span><span>"</span><span>,
</span><span>14</span>             <span>//</span><span>方法所在页面和方法名  </span>
<span>15</span> <span>            url : </span><span>"</span><span>../Home/User/GetPreViewXml</span><span>"</span><span>,
</span><span>16</span> <span>            success : </span><span>function</span><span>(data) {
</span><span>17</span>                 <span>//</span><span>返回的数据用data.d获取内容   </span>
<span>18</span>                 <span>if</span><span> (data) {
</span><span>19</span> <span>                    OCXobj.StartTask_Preview_InWnd(data, </span><span>0</span><span>);
</span><span>20</span> <span>                }
</span><span>21</span> <span>            },
</span><span>22</span> <span>            error : </span><span>function</span><span>(err) {
</span><span>23</span> <span>                alert(</span><span>"</span><span>调用webservice过程中发生了错误!</span><span>"</span><span>);
</span><span>24</span> <span>            }
</span><span>25</span> <span>        });
</span><span>26</span> <span>    });
</span><span>27</span><span>38</span> <span></</span><span>script</span><span>></span>
<span>39</span> <span></</span><span>head</span><span>></span>
<span>40</span> <span><</span><span>body</span><span>></span>
<span>41</span> 
<span>42</span>     <span><</span><span>input </span><span>id</span><span>='previewXml' </span><span>value</span><span>='{$previewXml}' </span><span>type</span><span>='hidden' </span><span>/></span>
<span>43</span>     <span><</span><span>div</span><span>></span>
<span>44</span>         <span>    </span><span><</span><span>input </span><span>type</span><span>="button"</span><span> value</span><span>="开始预览"</span>
<span>45</span> <span>            id</span><span>="StartPlayView"</span> <span>/></span> <span><</span><span>br </span><span>/></span>
<span>46</span>         <span><</span><span>div </span><span>style</span><span>="width: 750px; float: left; overflow: hidden"</span><span>></span>
<span>47</span>             <span>   </span><span><</span><span>br </span><span>/></span> <span>    </span>
<span>48</span>             <span><!--</span><span> 添加预览控件(需要先在windows下注册) </span><span>--></span>
<span>49</span>             <span><</span><span>object </span><span>classid</span><span>="clsid:D5E14042-7BF6-4E24-8B01-2F453E8154D7"</span>
<span>50</span> <span>                id</span><span>="PlayViewOCX"</span><span> width</span><span>="750"</span><span> height</span><span>="450"</span><span> name</span><span>="ocx"</span><span>></span> <span></</span><span>object</span><span>></span>
<span>51</span>         <span></</span><span>div</span><span>></span>
<span>52</span>     <span></</span><span>div</span><span>></span>
<span>53</span> <span></</span><span>body</span><span>></span>
<span>54</span> <span></</span><span>html</span><span>></span>
Nach dem Login kopieren

控制器代码:

1 function GetPreViewXml() 2 { 3 $client = new \SoapClient("http://192.168.1.113/services/CmsService?wsdl"); 4 $funs = array( 5 $client->__getFunctions() 6 ); 7 8 $userLogin = new \stdClass(); 9 $userLogin->userName = 'admin'; 10 $userLogin->pwd = '5B9BD37AE194BCE2D53666BCB9D99B01'; 11 $userLogin->clientIp = '192.168.1.105'; 12 $userLogin->clientPort = '80'; 13 $userLogin->cmsUrl = 'http://192.168.1.113'; 14 15 $loginResponse = $client->__call("userLogin", array( 16 $userLogin 17 )); 18 19 $getCameraInfoByDeviceInfo = new \stdClass(); 20 $getCameraInfoByDeviceInfo->indexCode = 2; 21 $getCameraInfoByDeviceInfo->sessionId = $loginResponse->return->sessionId; 22 $getCameraInfoByDeviceInfoResponse = $client->__call("getCameraInfoByDeviceInfo", array( 23 $getCameraInfoByDeviceInfo 24 )); 25 26 $getPreviewParam = new \stdClass(); 27 $getPreviewParam->sessionId = $loginResponse->return->sessionId; 28 $cameraArray = $getCameraInfoByDeviceInfoResponse->return->cameraArray; 29 $cameraIndexCode = ''; 30 if (is_array($cameraArray)) { 31 $cameraIndexCode = $cameraArray[0]->indexCode; 32 } else { 33 $cameraIndexCode = $cameraArray->indexCode; 34 } 35 $getPreviewParam->cameraIndexCode = $cameraIndexCode; 36 37 $getPreviewParamResponse = $client->__call("getPreviewParam", array( 38 $getPreviewParam 39 )); 40 41 $this->ajaxReturn($getPreviewParamResponse->return->previewXml); 42 } View Code

 

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage