toplan / phpsms

:iphone::rocket:Probably the most intelligent, elegant sms send library in php
MIT License
641 stars 129 forks source link

腾讯的接口1004错误 #141

Open Quinndark opened 6 years ago

Quinndark commented 6 years ago

出现1004错误 [{"driver":"Qcloud","time":{"started_at":"0.33102900 1507352277","finished_at":"0.60767200 1507352277"},"success":false,"result":{"info":"{\"result\":1004,\"errmsg\":\"package format errorcannot get \/tel\/mobile\"}","code":1004}}]

ahu commented 6 years ago

我也是...我去,折腾了一天了

youngerrainbow commented 6 years ago

@ahu 你是怎么修复的?

ahu commented 6 years ago

@youngerrainbow 未及修复...先绕开了

youngerrainbow commented 6 years ago

@ahu 好像官方有兼容,是不是哪里调用不对?

ahu commented 6 years ago

@youngerrainbow 只能等回头细看了:)

youngerrainbow commented 6 years ago

@ahu post 格式不对,给成 json 数组用 数字key 就可以了,我测试ok了

fengerwoo commented 6 years ago

@youngerrainbow 具体怎么改?

ahu commented 6 years ago

@DreamboyA @youngerrainbow 我是直接修改了 QcloudAgent.php 把所有 'tel'=>$to 改为了 'tel' => ['nationcode' => '86', 'mobile' => $to] 解决的。另外需要注意的是template date 里定义的参数一定要跟你申请的模板一致

dm521 commented 5 years ago

@ahu 多谢你的分享。这个问题,还需要把format_mobile 方法注释掉。

leemem commented 5 years ago

@dm521 @ahu 多谢分享,我修改QcloudAgent.php 中的formatMobile,可以正常发送

public function formatMobile(array $list)
{
    $list = array_map(function ($value) {
        return [
            'nationcode'    => $value['nation'],
            'mobile'        => $value['number'],
        ];
    }, array_filter($list, function ($value) {
        return is_array($value);
    }));
    return count($list) === 1 ? array_pop($list) : array_values($list);
}

修改为:

public function formatMobile(array $list)
{
    $list = array_map(function ($value) {
        return [
            'nationcode'    => is_string($value) ? '86' : $value['nation'],
            'mobile'        => is_string($value) ? $value : $value['number'],
        ];
    }, array_filter($list, function ($value) {
        return is_array($value) || is_string($value);
    }));
    return count($list) === 1 ? array_pop($list) : array_values($list);
}