<?php
/**
 * Created by NetBeans.
 * User : hj
 * Date : 2017.12.6
 * Time : 16:14
 * Intro: 
 */

namespace app\api\untils;

class Message {
    
    public function __construct() {
        
    }
    
    /**
     * 短信验证码
     * 容云通讯
     *
     * @param $to
     * @param $datas
     * @param string $tempId
     * @return SimpleXMLElement[]
     */
    public function sendCCPSMS($to, $datas, $tempId = '79972') {
        import('CCPRestSDK', EXTEND_PATH, '.php');
        $accountSid   = '8a48b55153eae51101540e763d3b3888';
        $accountToken = '26b220de299d4a56a6f54dd5792a30e4';
        $appId        = '8a48b55153eae51101540e77d1603891';
        $serverIP     = 'app.cloopen.com';
        $serverPort   = '8883';
        $softVersion  = '2013-12-26';


        // 初始化REST SDK
        //global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
        $rest = new \REST($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);

        $result = (array)$rest->sendTemplateSMS($to, $datas, $tempId);

        if($result == NULL ) {
            $data['statusMsg']  = '短信接口无返回';
            $data['statusCode'] = -1;
        }

        if($result['statusCode'] != 0) {
            $data['statusCode'] = $result['statusCode'];
            $data['statusMsg']  = $result['statusMsg'];
        }else{
            $data['statusCode'] = $result['statusCode'];
            $data['statusMsg']  = $result['statusMsg'];
            $data['TemplateSMS'] = $result['TemplateSMS'];
            $data['dateCreated'] = $result['dateCreated'];
            $data['smsMessageSid'] = $result['smsMessageSid'];
        }

        return $data;
    }

}
