MMSTemplateDemo


代码示列


获取彩信模板(get请求)

<?php

/*
 * -------------------------mms_get--------------------------------- 
 */
$url = "https://api.mysubmail.com/mms/template";
$appid = "";
$appkey = "";
$sign_type = "";
$timestamp;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/service/timestamp.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];

//GET


$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['template_id'] = "L5pDb3";

if($sign_type == "md5"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    ksort($temp);
    reset($temp);
    unset($temp['signature']);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = md5($appid.$appkey.$str.$appid.$appkey);
}
if($sign_type == "sha1"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    unset($temp['signature']);
    ksort($temp);
    reset($temp);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = sha1($appid.$appkey.$str.$appid.$appkey);
}

$api = $url."?".http_build_query($post_data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);


提交一个彩信模板(post请求)

<?php

/*
 * -------------------------mms_post--------------------------------- 
 */
$url = "https://api.mysubmail.com/mms/template";
$appid = "";
$appkey = "";
$sign_type = "";
$timestamp;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/service/timestamp.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];

//POST


$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['mms_title'] = "test";
$post_data['mms_signature'] = "【SUBMAIL】";
$post_data['mms_subject'] = "这是一条测试彩信";


$page1['text'] = "page1";
$page2['text'] = "page2";

$post_data['mms_content'] = json_encode(array($page1,$page2));

if($sign_type == "md5"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    ksort($temp);
    reset($temp);
    unset($temp['signature']);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = md5($appid.$appkey.$str.$appid.$appkey);
}
if($sign_type == "sha1"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    unset($temp['signature']);
    ksort($temp);
    reset($temp);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = sha1($appid.$appkey.$str.$appid.$appkey);
}


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);



修改彩信模板(put请求)

<?php

/*
 * -------------------------mms_post--------------------------------- 
 */
$url = "https://api.mysubmail.com/mms/template";
$appid = "";
$appkey = "";
$sign_type = "";
$timestamp;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/service/timestamp.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];

//PUT
$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['mms_title'] = "test";
$post_data['mms_signature'] = "【SUBMAIL】";
$post_data['mms_subject'] = "这是一条测试彩信";
$post_data['template_id'] = "";


$page1['text'] = "new page1";
$page2['text'] = "new page2";

$post_data['mms_content'] = json_encode(array($page1,$page2));

if($sign_type == "md5"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    ksort($temp);
    reset($temp);
    unset($temp['signature']);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = md5($appid.$appkey.$str.$appid.$appkey);
}
if($sign_type == "sha1"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    unset($temp['signature']);
    ksort($temp);
    reset($temp);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = sha1($appid.$appkey.$str.$appid.$appkey);
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);



删掉彩信模板(delete请求)

<?php

/*
 * -------------------------mms_post--------------------------------- 
 */
$url = "https://api.mysubmail.com/mms/template";
$appid = "";
$appkey = "";
$sign_type = "";
$timestamp;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/service/timestamp.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];

//delete


$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['template_id'] = "";

if($sign_type == "md5"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    ksort($temp);
    reset($temp);
    unset($temp['signature']);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = md5($appid.$appkey.$str.$appid.$appkey);
}
if($sign_type == "sha1"){
    $post_data['sign_type'] = $sign_type;
    $post_data['timestamp'] = $timestamp;
    $temp = $post_data;
    unset($temp['signature']);
    ksort($temp);
    reset($temp);
    $str = "";
    foreach ($temp as $key => $value) {
        $str.=$key."=".$value."&";
    }
    $str = substr($str,0,count($str)-2);
    $post_data['signature'] = sha1($appid.$appkey.$str.$appid.$appkey);
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);