国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊(cè) 詳解阿里大魚短信使用

詳解阿里大魚短信使用

Mar 29, 2017 pm 05:04 PM

我在做畢設(shè),項(xiàng)目中想用短信驗(yàn)證功能,就找到了阿里大魚,價(jià)格貌似目前最低,其他什么都好弄,就是導(dǎo)入到項(xiàng)目中,不知道怎么用,一直報(bào)錯(cuò),網(wǎng)上查了,大都是和文檔案例一樣,沒用,tp里還有專欄范例,估計(jì)都是舊版本,也沒用。最后搞出來(lái)了,特在此記錄一下。
下載SDK,解壓引入Autoload.php、TopSdk.php及aliyun和top兩個(gè)文件夾。
我引入的位置是 APP_PATH/Common/Lib/Alidayu/,不動(dòng)tp文件我覺得好些。
新建一個(gè)類文件 SendMSM.class.php,這個(gè)根據(jù)自己需求來(lái)。

<?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;短信測(cè)試&#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 放到了單獨(dú)的配置文件,以便后期重置了可以在后臺(tái)修改。

然后就是使用了,

<?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);
    }
}

測(cè)試結(jié)果:

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)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)