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

namespace app\api\untils;

class MessageUntils {
    
    public function __construct() {
        
    }
    
    /**
     * 短信验证码
     * 容云通讯
     *
     * @param $to
     * @param $datas
     * @param string $tempId
     * @return SimpleXMLElement[]
     */
    public function sendCCPSMS($to, $datas, $tempId = '214759') {
        import('CCPRestSDK', EXTEND_PATH, '.php');
        $accountSid   = '8a48b55153eae51101540e763d3b3888';
        $accountToken = '26b220de299d4a56a6f54dd5792a30e4';
        $appId        = '8a216da85f5c89b1015f7718e2b90a63';
        $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['statusCode']    = '';
        $result['statusMsg']     = '';
        $result['TemplateSMS']   = '';
        $result['dateCreated']   = '';
        $result['smsMessageSid'] = '';
        $result['statusMsg']     = '';
        $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['TemplateSMS']   = $result['TemplateSMS'];
        }

        return $data;
    }

}
