overtrue / easy-sms

📲 一款满足你的多种发送需求的短信发送组件
MIT License
3.1k stars 542 forks source link

修改yunxin无通知模板问题 #331

Open xugames opened 2 years ago

xugames commented 2 years ago

近日使用网易云信通知短信,报错,经检查无云信通知模板短信格式 做一下修改 `switch ($action) { case 'sendCode': $params = $this->buildSendCodeParams($to, $message, $config);

            break;
        case 'sendTemplate':
            $params = $this->buildSendMsgParams($to, $message, $config);
            break;
        case 'verifyCode':
            $params = $this->buildVerifyCodeParams($to, $message);

            break;
        default:`

新增sendTemplate 以及参数格式函数buildSendMsgParams `public function buildSendMsgParams(PhoneNumberInterface $to, MessageInterface $message, Config $config) {

    $data = $message->getData($this);
    $template = $message->getTemplate($this);

    if (!array_key_exists('params', $data)) {
        throw new GatewayErrorException('"params" cannot be empty', 0);
    }
    return [
        'mobiles' => json_encode([$to->getUniversalNumber()]),
        'templateid' => is_string($template) ? $template : '',
        'params'=>array_key_exists('params', $data) ? $data['params'] : '',
        'needUp' => $config->get('need_up', false),
    ];
}`

使用方法 $massage=[ 'template' => 'xxxx', 'data' => [ 'params' =>json_encode([$params]), 'action' => 'sendTemplate', ], ];

overtrue commented 2 years ago

欢迎 PR