S05GK接口如何实现高效短信发送?
- 内容介绍
- 文章标签
- 相关推荐
本文共计391个文字,预计阅读时间需要2分钟。
S05GK接口发送短信PHP代码示例:使用PHP的fsockopen方法调用短信接口,可模拟POST请求发送短信内容、接收号等。以下是一个示例:
php
// 短信内容$message='您好,这是测试短信内容。';
// 接收号码$phone='接收号码';
// 用户名和密码$username='用户名';$password='密码';
// 初始化POST数据$data=http_build_query([ 'username'=> $username, 'password'=> $password, 'phone'=> $phone, 'message'=> $message]);
// 创建socket连接$connection=fsockopen('ssl://sms服务商提供的接口地址', 443, $errno, $errstr, 30);
if (!$connection) { die(连接失败: $errstr ($errno)\n);}
// 发送POST请求fputs($connection, POST $apiUrl HTTP/1.1\r\n);fputs($connection, Host: sms服务商提供的接口地址\r\n);fputs($connection, Content-Type: application/x-www-form-urlencoded\r\n);fputs($connection, Content-Length: . strlen($data) . \r\n);fputs($connection, Connection: close\r\n\r\n);fputs($connection, $data);
// 获取响应$response='';while (!feof($connection)) { $response .=fgets($connection, 128);}
// 关闭连接fclose($connection);
// 处理响应echo $response;?>
S05GK接口发送短信PHP代码样例1、用PHP调用短信接口可以采用PHP的fsockopen方法调用服务商提供的接口,相关发送的信息如短信内容、接收号码等都可以通过模拟的POST函数方式提交。下面是摘自速达移动(sudas.cn)的接口样例文档中关于接口调用的代码。
封装发送的sms.php源码:
2、调用发送的sms_demo.php源码:
1.[代码][PHP]代码
<?php function Post($data, $target) { $url_info = parse_url($target); $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>表示成功,其它的参考文档 ?>
本文共计391个文字,预计阅读时间需要2分钟。
S05GK接口发送短信PHP代码示例:使用PHP的fsockopen方法调用短信接口,可模拟POST请求发送短信内容、接收号等。以下是一个示例:
php
// 短信内容$message='您好,这是测试短信内容。';
// 接收号码$phone='接收号码';
// 用户名和密码$username='用户名';$password='密码';
// 初始化POST数据$data=http_build_query([ 'username'=> $username, 'password'=> $password, 'phone'=> $phone, 'message'=> $message]);
// 创建socket连接$connection=fsockopen('ssl://sms服务商提供的接口地址', 443, $errno, $errstr, 30);
if (!$connection) { die(连接失败: $errstr ($errno)\n);}
// 发送POST请求fputs($connection, POST $apiUrl HTTP/1.1\r\n);fputs($connection, Host: sms服务商提供的接口地址\r\n);fputs($connection, Content-Type: application/x-www-form-urlencoded\r\n);fputs($connection, Content-Length: . strlen($data) . \r\n);fputs($connection, Connection: close\r\n\r\n);fputs($connection, $data);
// 获取响应$response='';while (!feof($connection)) { $response .=fgets($connection, 128);}
// 关闭连接fclose($connection);
// 处理响应echo $response;?>
S05GK接口发送短信PHP代码样例1、用PHP调用短信接口可以采用PHP的fsockopen方法调用服务商提供的接口,相关发送的信息如短信内容、接收号码等都可以通过模拟的POST函数方式提交。下面是摘自速达移动(sudas.cn)的接口样例文档中关于接口调用的代码。
封装发送的sms.php源码:
2、调用发送的sms_demo.php源码:
1.[代码][PHP]代码
<?php function Post($data, $target) { $url_info = parse_url($target); $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>表示成功,其它的参考文档 ?>

