<?php
namespace crmeb\services;
use think\facade\Db;

/**
 * 短信服务
 * Class SMSService
 * @package crmeb\services
 */
class ZjSMSServerService
{
    private static $userid = '15889';
    private static $username = "yflkj";
    private static $passwd = 'yfl831**';
    //验证码
    const VERIFICATION_CODE = 518076;
    //支付成功
    const PAY_SUCCESS_CODE = 520268;
    //发货提醒
    const DELIVER_GOODS_CODE = 520269;
    //确认收货提醒
    const TAKE_DELIVERY_CODE = 520271;
    //管理员下单提醒
    const ADMIN_PLACE_ORDER_CODE = 520272;
    //管理员退货提醒
    const ADMIN_RETURN_GOODS_CODE = 520274;
    //管理员支付成功提醒
    const ADMIN_PAY_SUCCESS_CODE = 520273;
    //管理员确认收货
    const ADMIN_TAKE_DELIVERY_CODE = 520422;
    /**
     * get: 发送短信验证码
     * path: sendSmsCode
     * method: sendSmsCode
     * param: phone - {string} 手机号
     */
    public  static function send($phone, array  $param ,$template="VERIFICATION_CODE")
    {
        $code = $param['code'];
        $target = "http://sms.izjun.cn/v2sms.aspx";
        $company = sys_config('site_name');
        //$company = "LALA NFT";
        switch ($template)
        {
            case 'PAY_SUCCESS_CODE':
                break;
            case 'DELIVER_GOODS_CODE':
                break;
            case  'TAKE_DELIVERY_CODE':
                break;
            case 'ADMIN_PLACE_ORDER_CODE':
                break;
            case 'ADMIN_RETURN_GOODS_CODE':
                break;
            case 'ADMIN_PAY_SUCCESS_CODE':
                break;
            case 'ADMIN_TAKE_DELIVERY_CODE':
                break;
            default:
                $content=sprintf('【%s】您的注册验证码为：%d 。验证码有效期为%d分钟，请尽快填写！',$company,$code,5);
        }
        $time = date("YmdHis",time());
       $data = [
            'action'=>'send',
            'userid'=>self::$userid,
            'timestamp'=>$time,
            'sign'=>md5(self::$username.self::$passwd.$time),
            'mobile'=>$phone,
            'content'=>$content,
            'sendTime'=>'',
            'extno'=>'',
            'rt'=>'json',
        ];
        $gets = json_decode(HttpService::postRequest($target,$data),true);
        if($gets){
            return  ['status' => 200, 'msg' => '短信发送成功'];

        }else{
            return ['status' => 400, 'msg' => '发送失败'];
        }
    }
}