suchen
Heimphp教程php手册详解阿里大鱼短信使用

我在做毕设,项目中想用短信验证功能,就找到了阿里大鱼,价格貌似目前最低,其他什么都好弄,就是导入到项目中,不知道怎么用,一直报错,网上查了,大都是和文档案例一样,没用,tp里还有专栏范例,估计都是旧版本,也没用。最后搞出来了,特在此记录一下。
下载SDK,解压引入Autoload.php、TopSdk.php及aliyun和top两个文件夹。
我引入的位置是 APP_PATH/Common/Lib/Alidayu/,不动tp文件我觉得好些。
新建一个类文件 SendMSM.class.php,这个根据自己需求来。

<?php

namespace Lib\Alidayu;


include(&#39;TopSdk.php&#39;);
//就是下面两句把我搞惨了,别嫌弃,我只是入门了而已
use TopClient; 
use AlibabaAliqinFcSmsNumSendRequest;

class SendMSM {
    
    public function send($recNum=&#39;&#39;, $smsParam=&#39;&#39;, $smsTemplateCode=&#39;SMS_8525079&#39;, $smsFreeSignName=&#39;短信测试&#39;){
        $c = new TopClient;
        $c->format = "json";
        $c->appkey = C(&#39;AlidayuAppKey&#39;);
        $c->secretKey = C(&#39;AlidayuAppSecret&#39;);
        $req = new AlibabaAliqinFcSmsNumSendRequest;
        //$req->setExtend("123456");
        $req->setSmsType("normal");
        $req->setSmsFreeSignName($smsFreeSignName);
        $req->setSmsParam($smsParam);
        $req->setRecNum($recNum);
        $req->setSmsTemplateCode($smsTemplateCode);
        $resp = $c->execute($req);
        return $resp;
    }
    
}

我把AppKey 和 secret 放到了单独的配置文件,以便后期重置了可以在后台修改。

然后就是使用了,

<?php
namespace Admin\Controller;

use Think\Controller;
use Lib\Alidayu\SendMSM;

class IndexController extends Controller {
    public function index(){
        $this->sendMSM();
    }
    
    protected function sendMSM(){
        $alidayu = new SendMSM();
        $result = $alidayu->send(&#39;13000000000&#39;,&#39;{"code":"123456"}&#39;);
        dump($result);
    }
}

测试结果:

object(stdClass)[11]
  public &#39;result&#39; => 
    object(stdClass)[12]
      public &#39;err_code&#39; => string &#39;0&#39; (length=1)
      public &#39;model&#39; => string &#39;101550887105^1102084861016&#39; (length=26)
      public &#39;success&#39; => boolean true
  public &#39;request_id&#39; => string &#39;12cl9hupqvkgh&#39; (length=13)
Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat -Befehle und wie man sie benutzt
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

SublimeText3 Englische Version

SublimeText3 Englische Version

Empfohlen: Win-Version, unterstützt Code-Eingabeaufforderungen!

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

MantisBT

MantisBT

Mantis ist ein einfach zu implementierendes webbasiertes Tool zur Fehlerverfolgung, das die Fehlerverfolgung von Produkten unterstützen soll. Es erfordert PHP, MySQL und einen Webserver. Schauen Sie sich unsere Demo- und Hosting-Services an.

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft