Home  >  Article  >  PHP Framework  >  Example to explain how TP framework integrates Huawei Cloud SMS service

Example to explain how TP framework integrates Huawei Cloud SMS service

藏色散人
藏色散人forward
2022-11-18 17:02:262010browse

The following thinkphp framework tutorial column will introduce to you how ThinkPHP integrates Huawei Cloud SMS Service. I hope it will be helpful to friends in need!

Example to explain how TP framework integrates Huawei Cloud SMS service

ThinkPHP integrates Huawei Cloud SMS service

This project integrates Huawei Cloud SMS sending service and supports ThinkPHP5.0 and ThinkPHP5. 1 and ThinkPHP6.0, maintained by Ningbo Shengjia Network Technology Co., Ltd.

Installation tutorial

Use composer require singka/singka-hwsms to install from the command line. [Recommended learning: "thinkPHP Video Tutorial"]

Usage examples (based on ThinkPHP6.0)

<?php
// +----------------------------------------------------------------------
// | 胜家云 [ SingKa Cloud ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.singka.net All rights reserved.
// +----------------------------------------------------------------------
// | 宁波晟嘉网络科技有限公司
// +----------------------------------------------------------------------
// | Author: ShyComet <shycomet@qq.com>
// +----------------------------------------------------------------------
namespace app\home\controller;

use SingKa\HwSms\HwSms;

class Index
{
    /**
    * 短信发送示例
    *
    * @url              华为云短信APP接入地址+接口访问URI
    * @appKey           华为云短信appKey
    * @appSecret        华为云短信appSecret
    * @sender           国内短信签名通道号或国际/港澳台短信通道号
    * @signature        华为云短信签名
    * @statusCallback   短信发送状态返回接收地址,可以为空
    */
    public function smsDemo()
    {
        $config[&#39;url&#39;] = &#39;https://rtcsms.cn-north-1.myhuaweicloud.com:10743&#39;;
        $config[&#39;appKey&#39;] = &#39;PkT889B*************wM0GAi&#39;;
        $config[&#39;appSecret&#39;] = &#39;U58fd****************0o4N&#39;;
        $config[&#39;sender&#39;] = &#39;csms12345678&#39;;
        $config[&#39;signature&#39;] = &#39;短信签名&#39;;
        $config[&#39;statusCallback&#39;] = &#39;短信发送状态返回接收地址,可以为空&#39;;
        $sms = new HwSms($config);
        $result = $sms->send(&#39;模板ID&#39;, &#39;手机号码(多个号码可以用英文逗号隔开)&#39;, &#39;短信变量数组&#39;);
        if ($result[&#39;code&#39;] == &#39;000000&#39;) {
            echo &#39;发送成功&#39;;
        } else {
            echo $result[&#39;msg&#39;];
        }
    }
  
}

Other instructions

华为云短信介绍:https://support.huaweicloud.com/productdesc-msgsms/sms_desc.html

The above is the detailed content of Example to explain how TP framework integrates Huawei Cloud SMS service. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete