Lesson24 At the Aireport 2

At the Airport 在机场

Dialogue A

A: Please fill out these tags and attach them to your suitcases. Then put them on the scale.

B: OK.

A: I’m afraid your luggage is overweight. You’ll have to pay an excess baggage charge.

B: How much will that be?

A: Let me see – US$10.

B: That’s not too bad.

Dialogue B

A: Here are your tickets. The baggage claim stubs are attached to them.

B: Thank you.

A: And here is your boarding pass. You board at Gate 12.

B: OK. Is that all?

A: No. Please wait here till your luggage goes through the X-ray machine.

B: OK.

A: Have a nice flight.

B: Thank you.

阿里云滑动验证码集成-composer版本

可使用的composer

  • dy7338/aliyun-php-sdk-afs
  • oygza/aliyun-php-sdk-afs

oygza/aliyun-php-sdk-afs 使用

dy7338-aliyun-php-sdk-afs 使用

dy7338/aliyun-php-sdk-afs地址: https://packagist.org/packages/dy7338/aliyun-php-sdk-afs

安装: composer require dy7338/aliyun-php-sdk-afs

在控制器的方法中

$iClientProfile = \ DefaultProfile::getProfile ("cn-hangzhou", "YOUR ACCESSKEY", "YOUR ACCESS_SECRET");
$client = new \ DefaultAcsClient($iClientProfile);
\ DefaultProfile::addEndpoint ("cn-hangzhou", "cn-hangzhou", "afs", "afs.aliyuncs.com");

$request = new \ afs\Request\V20180112\AuthenticateSigRequest();
$request->setSessionId ($sessionid);// 必填参数,从前端获取,不可更改,android和ios只变更这个参数即可,下面参数不变保留xxx
$request->setToken ($token);// 必填参数,从前端获取,不可更改
$request->setSig ($sig);// 必填参数,从前端获取,不可更改
$request->setScene ($scene);// 必填参数,从前端获取,不可更改
$request->setAppKey ($appkey);//必填参数,后端填写
$request->setRemoteIp (xxxx);//必填参数,后端填写

$response = $client->doAction ($request);//返回code 100表示验签通过,900表示验签失败
var_dump($response);

方式二-使用use

use DefaultProfile;
use DefaultAcsClient;
use afs\Request\V20180112\AuthenticateSigRequest;

$iClientProfile = DefaultProfile::getProfile ("cn-hangzhou", "YOUR ACCESSKEY", "YOUR ACCESS_SECRET");
$client = new  DefaultAcsClient($iClientProfile);
DefaultProfile::addEndpoint ("cn-hangzhou", "cn-hangzhou", "afs", "afs.aliyuncs.com");

$request = new AuthenticateSigRequest();
$request->setSessionId ($sessionid);// 必填参数,从前端获取,不可更改,android和ios只变更这个参数即可,下面参数不变保留xxx
$request->setToken ($token);// 必填参数,从前端获取,不可更改
$request->setSig ($sig);// 必填参数,从前端获取,不可更改
$request->setScene ($scene);// 必填参数,从前端获取,不可更改
$request->setAppKey ($appkey);//必填参数,后端填写
$request->setRemoteIp ('xxxx');//必填参数,后端填写

$response = $client->doAction ($request);//返回code 100表示验签通过,900表示验签失败
dump($response);

相关资料

阿里云滑动验证码集成-thinkphp3.2版本
oygza-aliyun-php-sdk-afs安装出错处理

阿里云滑动验证码集成-thinkphp3.2版本

资料准备

  • 阿里云账号
  • Access Key http://i.aliyun.com/access_key

前端集成

参考官方文档: https://help.aliyun.com/document_detail/66317.html

后端集成

下载SDK后解压后重命名文件夹aliyunPhpSdkAfs复制到ThinkPHP/Library/Vendor/

<?php
namespace Home\Controller;
include_once  VENDOR_PATH . 'aliyunPhpSdkAfs/aliyun-php-sdk-core/Config.php';
use Afs\Request\V20180112 as Afs;

    public function ajaxNoCaptcha()
    {

        $iClientProfile = \ DefaultProfile::getProfile("cn-hangzhou", "YOUR ACCESSKEY", "YOUR ACCESS_SECRET");
        $client = new \ DefaultAcsClient($iClientProfile);
        \ DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", "afs", "afs.aliyuncs.com");
        $request = new Afs\AuthenticateSigRequest();

        $request->setSessionId("xxxxxx");// 必填参数,有前端生成传入-对应JS中的 window.console && console.log(data.csessionid)
        $request->setToken("xxxx");// 必填参数,有前端生成传入-对应JS中的 window.console && console.log(nc_token)
        $request->setSig("xxxxx");// 必填参数,有前端生成传入 -对应JS中 window.console && console.log(data.sig)
        $request->setScene("xxxx");// 必填参数,类型, 阿里云控制获取-放在前端-再传到自己服务器中
        $request->setAppKey("xxxx");//必填参数,阿里云控制台获取
        $request->setRemoteIp("xxx");//必填参数,自己服务器获取的

        $response = $client->getAcsResponse($request);//response的code枚举:100验签通过,900验签失败
        print_r($response);

    }

相关资料

集成过程程序错误点这儿

阿里云滑动验证码集成-PHP版-问题记录

环境: mac-docker-Version 18.06.0-ce-mac70 (26399)

总结

thinkphp-3.2集成

问题出现主要是docker-代理造成的处理方法:点击docker图标 preferences – Proxies 把里面的配置 Manual proxy configuration 改成 Sysem proxy 

调试方法: PHP中用var_dump在这打印 /aliyunPhpSdkAfs/aliyun-php-sdk-core/DefaultAcsClient.php : 131 var_dump($body);

集成过程遇到到报错问题-记录

Error: HTTP Status: 400 RequestID: in /home/www-data/test_ks/ThinkPHP/Library/Vendor/aliyunPhpSdkAfs/aliyun-php-sdk-core/DefaultAcsClient.php on line 120

估计是本机环境问题-关闭 ShadowsocksX

/aliyunPhpSdkAfs/aliyun-php-sdk-core/DefaultAcsClient.php : 131 var_dump($body);

string(38) "Invalid header received from client.
"
Error: HTTP Status: 400 RequestID: in /home/www-data/test_ks/ThinkPHP/Library/Vendor/aliyunPhpSdkAfs/aliyun-php-sdk-core/DefaultAcsClient.php on line 120

启动了 ShadowsocksX, 并没有完全退出

string(277) "<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: connection refused</title>
</head><body>
The proxy could not connect ot 127.0.0.1:1087
<br>
<p>Server is <a href="https://github.com/moby/vpnkit">moby/vpnkit</a></p>
</body>
</html>
"
Error: HTTP Status: 503 RequestID: in /home/www-data/test_ks/ThinkPHP/Library/Vendor/aliyunPhpSdkAfs/aliyun-php-sdk-core/DefaultAcsClient.php on line 120

完全退出 ShadowsocksX 出现 – mac docker 中也有代理

preferences – Proxies 把里面的配置 Manual proxy configuration 改成 Sysem proxy 

代理改完后重启docker, 一切就正常了.

相关资料

打开“我的Access Key”页面

PHP-SDK使用说明
HTTP Status 400服务器返回 由于语法格式有误,服务器无法理解此请求。不作修改,客户程序就无法重复此请求

php报错 Cannot redeclare class

自己遇到的问题是: 在使用阿里云滑动验证SDK, 同时又找了一个composer包加载导致问题出现. 去除安装的composer包问题解决. 

导致问题出现的可能情况

  • 重复包含相同的类文件
  • 在同一个文件中重复声明了两次同名的类
  • 该类为PHP类库中内置的类。

相关资料

php报错:Cannot redeclare class 提示的解决方法
Fatal error: Cannot redeclare class 原因分析与解决办法

Lesson23 At the Airport

At the Airport 在机场

Dialogue A

A: This is the arrival lounge.

B: I know. Where is the departure lounge?

A: Come. Follow me.

B: There! The check-in counters are over there.

A: Dont’t we have to go pay the airport tax first?

B: No. We pay it after we check in.

Dialogue B

A: Good morning. May I have your passport, please?

B: Here you are.

A: Smoking or non-smoking?

B: Non-smoking

A: Aisle or window seat?

B: Window seat, please.

A: Do you have any luggage to check in?

B: Yes. This my carry-on luggage and I’ll check in these two suitcase.