Giter Site home page Giter Site logo

phpsms's People

Contributors

branchzero avatar cuikangyi avatar darkal avatar domainname avatar hinet avatar hzkoala avatar king19800105 avatar medz avatar toplan avatar yangliuyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpsms's Issues

怎样在phpsms.php文件中为自定义代理指定agentClass?

namespace App\Library;

use Toplan\PhpSms\Agent;
use Toplan\PhpSms\ContentSms;

class LanzSMSAgent extends Agent implements ContentSms

上面我自定义代理类的,phpsms.php配置文件是:

'scheme' => [
        'LanzSMS'
    ],
    'agents' => [
        //自定义代理
        'LanzSMS' => [
            'userId' => 'xx',
            'account' => 'xx',
            'password' => 'xxx',

        ]

然而程序是用这个$className = "Toplan\PhpSms\{$name}Agent";,如何在phpsms.php定义agentClass

lumen使用问题

我使用lumen做为API核心处理系统,现在想用这个类库进行短信发送,但是我发现一个问题,就是PhpSmsServiceProvider类里面返回的Sms类是没有初始化的,然后整个文档都是说用门面调用,但是lumen是默认禁用门面的,我尝试用app("PhpSms")的形式加载Sms类,但是因为没有初始化Sms,所以基本上不可用。希望后面能适配一下lumen的使用。

v2 版本接口规划,欢迎有兴趣的童鞋提建议

v2目前规划:

  • 关于代理器类:所有Agent类继承Toplan\PhpSms\Agent抽象类,把抽象类中发送相关的方法再抽离出来,定义成一系列接口,需要实现模版短信的实现TemplateSms接口,需要实现内容短信的实现ContentSms接口,语音也一样,以此类推。
  • 关于短信类:定义一个超级父类:Message, 规划的子类有Sms,TemplateSms,ContentSms,Voice,TemplateVoice,FileVoice,CodeVoice
Sms::to()->content()->template()->data()->send(); //短信全能类

TemplateSms::to()->template()->data()->send(); // TemplateSms非全能,没有content方法
  • 关于全局配置:定义一个新的类Dispacher来处理:
Dispacher::scheme(...);
Dispacher::config(...);
Dispacher::queue(...);
...

为什么唯独Log Scheme 发送失败

是这样的 在代码中 使用的是alidayu的scheme, 可以正常使用, 在写测试用例的时候 使用

Config::set('phpsms.scheme', ['Log']);

指定scheme 默认为Log 避免真的发送短信 但是问题来了 在代码环境中使用alidayu代码都能正常运作 甚至注释了Config这段代码 都可以正常运行,唯独在上述代码运作时 返回的success结果为false 这是为什么呢
附上日志及代码
使用send发送回来的结果dump后结果是

array:3 [
  "success" => false
  "time" => array:2 [
    "started_at" => "0.12025000 1504518904"
    "finished_at" => "0.12125500 1504518904"
  ]
  "logs" => array:1 [
    0 => array:4 [
      "driver" => "Log"
      "time" => array:2 [
        "started_at" => "0.12028900 1504518904"
        "finished_at" => "0.12123700 1504518904"
      ]
      "success" => false
      "result" => array:2 [
        "info" => null
        "code" => 0
      ]
    ]
  ]
]

发送的代码

$result = PhpSms::make()
            ->template($template)
            ->to($phone)
            ->data($data)
            ->send();

$template['Alidayu' => env('SMS_ALI_VERIFY_TEMPLATE')]
$datacompact('code')

发送后,如何记录详细的返回消息

你好,我现在正用阿里大于测试,可以判断发送失败或成功,但是我想记录返回的详细消息到数据库中。以方便排错之类。
请给一个返回结果的数据结构?
如何记录具体错误代码、详细错误消息?
如果使用其他服务商,返回的结果也是一样吗?

https://github.com/toplan/task-balancer 这里提到了$result结构,但是并没有关键细节,不太明白。

"toplan/phpsms": "~1.8.0-beta", composer update 报错

Problem 1
- Installation request for toplan/phpsms ~1.8.0-beta -> satisfiable by toplan/phpsms[1.8.0-beta.1].
- toplan/phpsms 1.8.0-beta.1 requires toplan/task-balancer ~0.5.0-beta -> satisfiable by toplan/task-balancer[0.5.0-beta.1] but these conflict with your requirements or minimum-stability.

qcloud短信api错误

{ "tel": { //如需使用国际电话号码通用格式,如:"+8613788888888" ,请使用sendisms接口见下注 "nationcode": "86", //国家码 "mobile": "13788888888" //手机号码 }, "type": 0, //0:普通短信;1:营销短信(强调:要按需填值,不然会影响到业务的正常使用) "msg": "你的验证码是1234", //utf8编码 "sig": "30db206bfd3fea7ef0db929998642c8ea54cc7042a779c5a0d9897358f6e9505", //app凭证,具体计算方式见下注 "time": 1457336869, //unix时间戳,请求发起时间,如果和系统时间相差超过10分钟则会返回失败 "extend": "", //通道扩展码,可选字段,默认没有开通(需要填空)。 //在短信回复场景中,腾讯server会原样返回,开发者可依此区分是哪种类型的回复 "ext": "" //用户的session内容,腾讯server回包中会原样返回,可选字段,不需要就填空。 }

注意电话号码那一部分。是tel:{} 不是接收固定号码

详情:
https://www.qcloud.com/document/api/382/5808

阿里云短信发送错误

  • 阿里云短信发送, 一直提示"InvalidTimeStamp.Expired"
  • 检查时间戳字段, 没有问题
  • 咨询技术客服, 回复如下
同时,在日志查看,您其实是有用户消息服务的batchSendSms接口发送的,并且在2017-06-23 14:58:26有成功。建议您继续调整使用batchSendSms接口发送。  
  • 客服说是接口调用url错误

YunTongXun 短信发送成功状态判断有误

现在短信发送成功判断用的是

$result->statusCode === 0

但实际上,云通讯的状态码是 000000 。所以现在短信发送成功了,但组件返回结果 $result['success'] 为 false

ps: 云通讯和云之讯的接口几乎一样的,只是某些接口路径有一点点不同,如果有时间的话,可以考虑改成共用一个 lib .

[版本号:1.8]自定义代理器的同学注意下

如果你们做自定义代理器,要注意库里的代码有一处有问题,
Toplan\PhpSms\Sms.php289行开始
代码是:

if (!empty($options)) {
    self::$agents[$name] = new ParasiticAgent($config, $options);
} elseif (class_exists($className)) {
    self::$agents[$name] = new $className($config);
} else {
    throw new PhpSmsException("Not support agent `$name`.");
}

这样如果你在phpsms.php里的scheme里以数组的形式设置了你的自定义代理器并加了weight
比如

'scheme' => [
    App\agents\AAA\Agent::class => [
        '20',
        'agentClass' => App\Libs\AAA\Agent::class
    ],
    App\agents\BBB\Agent::class => [
        '10 backup',
        'agentClass' => App\Libs\BBB\Agent::class
    ]
]

那么这两个Agent经过那段代码后,就跑ParasiticAgent去了。
所以,要不就不要有weight,这样的后果 我不知道会不会造成没有权重的特性了,
我也没多看其它代码,就把elseif改了一下

if (!empty($options)) {
    self::$agents[$name] = new ParasiticAgent($config, $options);
} 
if (class_exists($className)) {
    self::$agents[$name] = new $className($config);
} else {
    throw new PhpSmsException("Not support agent `$name`.");
}

希望遇到同样问题的同学能看到,着实弄了我半天。醉了!

能否提供一个队列实现的例子呢?

允许推入队列,并自定义队列实现逻辑(与队列系统松散耦合)。

比如 将队列存储到数据库,然后定时任务发送什么的. 要求比较过分, 不知道能否考虑.

同一个短信服务商多个apikey如何更好的切换?

由于审核原因,云片网的营销短信需要申请营销账号,因此会有两个apikey.
通过账号类型动态设置apikey没什么问题,但是有更好的解决方案么?
我自定义了YunPianAgent,想在Agent这边完成apikey的切换.
如果使用SMSManager,传递到Agent的业务数据已经被框架限制了.
` public function sendSms($to, $content, $tempId, array $data)
{
$this->sendContentSms($to, $content);
}

public function sendContentSms($to, $content)`

由于短信接口被调用的地方比较多,封装到Agent的话,只需要
正常使用SMSManager就可以了.

laravel5.4最新更新后php artisan 报错[ErrorException] Illegal offset type in unset

使用最新的laravel版本,使用本扩展,在执行php artisan时报错

[ErrorException] Illegal offset type in unset

debug后发现是这段代码出错,

$this->app->singleton([
            'Toplan\\Sms\\SmsManager' => 'laravel-sms',
        ], function ($app) {
            $token = $app->request->header('access-token', null);
            if (empty($token)) {
                $token = $app->request->input('access_token', null);
            }
            $input = $app->request->all();

            return new SmsManager($token, $input);
        });

猜测应该是新版本laravel的singletion绑定时不能再使用数组,
代码更改为如下后就正常了,

$this->app->singleton('Toplan\\Sms\\SmsManager', function ($app) {
            $token = $app->request->header('access-token', null);
            if (empty($token)) {
                $token = $app->request->input('access_token', null);
            }
            $input = $app->request->all();

            return new SmsManager($token, $input);
        });

希望可以发布一个新版本修复一下,谢谢

使用云片发送短信时报错

我把phpsms升级到1.8.0后云片发送短信时报错,我查看了下错误,应该是在Agent.php中curl()处循环读取$opts时报错,
foreach ($opts as $key => $value) {
curl_setopt($ch, $key, $value);
}
我将其改成
curl_setopt($ch, CURLOPT_SSL_POST,$opts[3]);
curl_setopt($ch, CURLOPT_SSL_HTTPHEADER,$opts[1]);
curl_setopt($ch, CURLOPT_SSL_POSTFIELDS,http_query_bulid($opts[0]));
curl_setopt($ch, CURLOPT_SSL_HTTPURL,$opts[4]);
以后就正常发送云片短信了。

建议增加故障判断自动切换机制

受限于网络或者运营商内部问题,即便在配置了比例、备份策略后,仍然要尽可能提高短信发送成功率。建议:

1.增加daemon程序,自动判断短信发送成功率,动态调整通道开关。能够自动开和关。甚至可以通过ui或者命令行,在不改代码的情况下,调整发送比例。

2.短信字符拆分策略,每家大同小异,但是依然可以配置是否在提交到短信服务商之前切分,还是直接发送长短信,因为各家针对拆分后的回调机制是不同的。

3.短信发送需要永久化保存,以便能够查询发送结果。

4.对于上行短信,需要配置是否支持扩展码,以自动对于下发内容。

以上4点是我们公司目前短信策略,供参考。

腾讯的接口1004错误

出现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}}]

laravel

$this->app->singleton([
'Toplan\Sms\SmsManager' => 'laravel-sms',
], function ($app) {
$token = $app->request->header('access-token', null);
if (empty($token)) {
$token = $app->request->input('access_token', null);
}
$input = $app->request->all();

        return new SmsManager($token, $input);
    });

composer更新到1.8.0版本 阿里大鱼 发送短信报错 Invalid signature

1.8.0版本发送短信: {"success":false,"time":{"started_at":"0.47898600 1498094446","finished_at":"0.53329300 1498094446"},"logs":[{"driver":"Alidayu","time":{"started_at":"0.47902900 1498094446","finished_at":"0.53327600 1498094446"},"success":false,"result":{"info":"{\"code\":25,\"msg\":\"Invalid signature\",\"request_id\":\"zlycsgi622v2\"}","code":25}}]}

固定版本到1.7.2 发送短信成功: {"success":true,"time":{"started_at":"0.53952600 1498095191","finished_at":"0.18113300 1498095192"},"logs":[{"driver":"Alidayu","time":{"started_at":"0.53955100 1498095191","finished_at":"0.18108200 1498095192"},"success":true,"result":{"info":"{\"err_code\":\"0\",\"model\":\"108284793846^1111232052740\",\"success\":true}","code":"0"}}]}

望解决回复

自定义代理器

自定义代理器类使用 Toplan/PhpSms 命名空间
对于Laravel项目 ,在重新执行 php artisan optimize ,生成的 autoload_classmap.php
中也不会出现自定义的类的相关映射.
$className = "Toplan\\PhpSms\\{$name}Agent";
class_exists($className);

建议增加发送短信条数限制

以防恶意调用接口,造成不必要的损失。
1.针对一个ip,限制次数。
2.针对一个手机号码,限制次数

另外,对于发送验证码的情况,我们要限制尝试次数。

beforeDriverRun建议

提供了beforeDriverRun 但是beforeDriverRun中无法标记当前agent 失效.

比如, 目前发送短信会有某个时间内的次数限制,当之前已经使用某agent进行发送了.之后又多次请求.

按理说,发送不成功应该不会计费, 但是目前的短信网关一般都是不发送,但是进行计费的.

如果在beforeDriverRun 时根据当前agent的判断, 进行当前agent跳过或直接标记agent错误,那就会好很多了.

聚合数据发送后判断错误

Toplan\PhpSms\JuHeAgent 方法genResult 使用if ($result['error_code'] === '0')判定,实际返回数据为0,所以永远发送失败

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.