PHP代码样例-S05GK接口发送短信

WBOY
リリース: 2016-06-06 19:39:20
オリジナル
1587 人が閲覧しました

S05GK接口发送短信PHP代码样例 1、用PHP调用短信接口可以采用PHP的fsockopen方法调用服务商提供的接口,相关发送的信息如短信内容、接收号码等都可以通过模拟的POST函数方式提交。下面是摘自速达移动(sudas.cn)的接口样例文档中关于接口调用的代码。 封装发

S05GK接口发送短信PHP代码样例

 1、用PHP调用短信接口可以采用PHP的fsockopen方法调用服务商提供的接口,相关发送的信息如短信内容、接收号码等都可以通过模拟的POST函数方式提交。下面是摘自速达移动(sudas.cn)的接口样例文档中关于接口调用的代码。
封装发送的sms.php源码:

2、调用发送的sms_demo.php源码:

<?php

function Post($data, $target) {
    $url_info = parse_url($target);
    $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
    $httpheader .= "Host:" . $url_info['host'] . "\r\n";
    $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
    $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
    $httpheader .= "Connection:close\r\n\r\n";
    //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
    $httpheader .= $data;

    $fd = fsockopen($url_info['host'], 80);
    fwrite($fd, $httpheader);
    $gets = "";
    while(!feof($fd)) {
        $gets .= fread($fd, 128);
    }
    fclose($fd);
    return $gets;
}
?>
ログイン後にコピー

<?php
include_once('sms.php');

$target = "http://sdk.sudas.cn/SmsMmsWebService/Service.asmx/g_Submit";
//替换成自己的测试账号,参数顺序和wenservice对应
$post_data = "sname=kwsm&spwd=kwsm&scorpid=&sprdid=101&sdst=13910862579&smsg=".rawurlencode("短信内容");
//$binarydata = pack("A", $post_data);
echo $gets = Post($post_data, $target);
//请自己解析$gets字符串并实现自己的逻辑
//<State>0</State>表示成功,其它的参考文档
?>
ログイン後にコピー

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!