Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

报错Warning: current() expects parameter 1 to be array, null given in vendor\flc\alidayu\src\Alidayu\Client.php on line 129 #6

Closed
xualen opened this issue Jan 25, 2017 · 7 comments

Comments

@xualen
Copy link

xualen commented Jan 25, 2017

代码如下:
require '/vendor/flc/alidayu/autoload.php';
use Flc\Alidayu\Client;
use Flc\Alidayu\App;
use Flc\Alidayu\Requests\AlibabaAliqinFcSmsNumSend;
use Flc\Alidayu\Requests\IRequest;

// 配置信息
$config = array(
'app_key' => '......',
'app_secret' => '......'
);

// 使用方法一
$client = new Client(new App($config));
$req = new AlibabaAliqinFcSmsNumSend;

$req->setRecNum('13000000000')
->setSmsParam([
'number' => rand(100000, 999999)
])
->setSmsFreeSignName('...')
->setSmsTemplateCode('SMS_10000000');

$resp = $client->execute($req);
报错:
Warning: current() expects parameter 1 to be array, null given in E:\web\vendor\flc\alidayu\src\Alidayu\Client.php on line 129

@royalwang
Copy link

你的请求返回值是Null,json解析空也是Null,然后用来current取值就报参数应该是个数组,不能用Null值。

@flc1125
Copy link
Owner

flc1125 commented May 27, 2017

是的。一般出現這種情況,是網絡原因導致的。建議在最外層增加一個try catch

@Tinywan
Copy link

Tinywan commented Aug 8, 2017

  • 我也是这个错误:current() expects parameter 1 to be array, null given
     * 解析返回数据
     * @return array|false
     */
    protected function parseRep($response)
    {
        if ($this->format == 'json') {
            $resp = json_decode($response);

            if (false !== $resp) {
                $resp = current($resp);
            }
        }

        elseif ($this->format == 'xml') {
            $resp = @simplexml_load_string($response);
        }

        else {
            throw new Exception("format错误...");
  • 加上 try catch 同样一样的,返回错误信息:current() expects parameter 1 to be array, null given
    protected function parseRep($response)
    {
        try {
            if ($this->format == 'json') {
                $resp = json_decode($response);
                if (false !== $resp) {
                    $resp = current($resp);
                }
            } elseif ($this->format == 'xml') {
                $resp = @simplexml_load_string($response);
            } else {
                throw new Exception("format错误...");
            }
        } catch (\Exception $e) {
            $resp = $e->getMessage();
        }

        return $resp;
    }
  • @flc1125 这个有什么办法可以解决吗?公司里是好的,结果回家就会出现这个情况

@Tinywan
Copy link

Tinywan commented Aug 8, 2017

@xualen 这个问题你解决了没有?

@flc1125
Copy link
Owner

flc1125 commented Aug 9, 2017

这块我重新发布一个版本专门修复下吧!

@flc1125
Copy link
Owner

flc1125 commented Aug 12, 2017

已修复。已更新packagist

@flc1125 flc1125 closed this as completed Aug 12, 2017
@Tinywan
Copy link

Tinywan commented Aug 12, 2017

@flc1125 可以的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants