<?php
namespace Ruifi\App; class SmsL
{ public function smsIcode($moblie,$sms_code,$intl_code){
header("Content-Type:text/html;charset=utf-8");
$apikey = "";
$mobiles = "+".$intl_code.$moblie;
$text = "Shixi";
$smsArrL = array(
"apikey" => "$apikey",
"mobile" => "$mobiles",
"text" =>"$text"
);
$smsArrL_to = \Ruifi\Service\CommonService::gbk_to_utf8_arr($smsArrL); //编码转换
$apikey = $smsArrL_to['apikey'];
$mobilesm = $smsArrL_to['mobile'];
/* $mobiles = urlencode("$mobile");
$mobiles = urlencode("$mobiles");*/
//$text = $smsArrL_to['text']; $ch = curl_init();
/* 设置验证方式 */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
/* 设置返回结果为流 */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/* 设置超时时间*/
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
/* 设置通信方式 */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 发送短信
/* $data=array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
$json_data = $this->send($ch,$data);
$array = json_decode($json_data,true); return $array;*/ // 发送模板短信
// 需要对value进行编码
$data = array('tpl_id' => '2009674', 'tpl_value' => ('#code#').
'='.urlencode("$sms_code"), 'apikey' => $apikey, 'mobile' => $mobilesm);
$json_data = $this->tpl_send($ch,$data);
$array = json_decode($json_data,true);
return $array; curl_close($ch);
} /************************************************************************************/ function send($ch,$data){
curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result = curl_exec($ch);
$error = curl_error($ch);
$this->checkErr($result,$error);
return $result;
}
function tpl_send($ch,$data){
curl_setopt ($ch, CURLOPT_URL,
'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result = curl_exec($ch);
$error = curl_error($ch);
$this->checkErr($result,$error);
return $result;
}
function checkErr($result,$error) {
if($result === false)
{
echo 'Curl error: ' . $error;
}
else
{
//echo '操作完成没有任何错误';
}
} }

调用:

//传递手机号 验证码 和 国家区号
$SmssL = new \Ruifi\App\SmsL();
$Code = $SmssL->smsIcode("$mobile","$sms_code","$intl_code"); if ($Code['code'] == '0'){
$codeState = 'OK';
}

php 云片国外短信实例的更多相关文章

  1. asp.net C# 实现阿里大鱼和云片网短信接口类

    云片网短信通用类 public class YunpianSMS { public YunpianSMS() { } /// <summary> /// 服务器HTTP地址 /// < ...

  2. php 阿里云国内短信实例

    调用:先去阿里云申请短信服务 $smsArr = array( "accessKeyId" => "", // key "accessKeySe ...

  3. PhpSms 稳定可靠的php短信发送库

    可能是目前最聪明.优雅的PHP短信发送库了.从此不再为各种原因造成的个别短信发送失败而烦忧! phpsms的任务均衡调度功能由toplan/task-balancer提供. GitHub地址:http ...

  4. thinkphp实现短信验证注册

    前言 注册时经常需要用到短信验证码,本文记录一下思路和具体实现. 短信验证平台使用云片,短信验证码的生成使用thinkphp. 思路 1.用户输入手机号,请求获取短信验证码. 2.thinkphp生成 ...

  5. PHP短信发送服务 youe短信企业服务

    /** * 通用短信平台HTTP接口POST方式发送短信实例 * 返回字符串 * 一般情况下调用此方法 */ function postSendMessage($msgContents,$phoneL ...

  6. Android中实现短信发送的一种方式

    SendSmsActivity.java: package com.test.smsmangerdemo.sendsmsactivity; import android.support.v7.app. ...

  7. Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)

    结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...

  8. 云片-语音验证码--短信验证码 - PHP接口

    ///////////////////////语音验证///////////////////////////// /**  * 发送短信(语音验证码)云片语音服务  * @param  $apikey ...

  9. 微信小程序发送短信验证码完整实例

    微信小程序注册完整实例,发送短信验证码,带60秒倒计时功能,无需服务器端.效果图: 代码: index.wxml <!--index.wxml--> <view class=&quo ...

随机推荐

  1. jquery验证时间

    http://blog.csdn.net/guguojin/article/details/7045908 验证时间的正则表达式集合 //日期格式yyyy  PatternsDict.date_y= ...

  2. Mysql数据库简单使用(二)

    Mysql导入.sql文件 进入数据库(要导入的数据库) 数据库中有要导入.sql文件名的数据库,没有则新建. source 路径+文件名 souce /home/robot/csql.sql 数据库 ...

  3. http状态码-备查

    http状态码分类 分类 分类描述 1** 信息,服务器收到请求,需要请求者继续执行操作 2** 成功,操作被成功接收并处理 3** 重定向,需要进一步的操作以完成请求 4** 客户端错误,请求包含语 ...

  4. filter方法求出列表所有奇数并构造新列

    a = [, , , , , , , , , ] b = filter(lambda x: x % != , a) for i in b: print(i)

  5. [Codeforces1148C]Crazy Diamond——构造

    题目链接: [Codeforces1148C]Crazy Diamond 题目大意: 给出一个$1\sim n$的排列要求将其排序,每次能交换两个位置的数当且仅当这两个位置下标差的绝对值大于等于$\f ...

  6. OpenFOAM 中边界条件的设定【转载】

    转载自:http://blog.sina.com.cn/s/blog_a0b4201d0102v7jt.html 用习惯了FLUENT的操作界面,再使用OpenFOAM就会觉得非常繁琐.遇到的第一个问 ...

  7. 分布式文件上传 spring boot + fastdfs + dropzone

    1.首先安装fastDFS 参考链接: https://www.funtl.com/zh/spring-cloud-itoken-codeing/%E5%88%86%E5%B8%83%E5%BC%8F ...

  8. LC 991. Broken Calculator

    On a broken calculator that has a number showing on its display, we can perform two operations: Doub ...

  9. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  10. angular自定义组件

    https://cli.angular.io/ 打开终端创建header组件: ng g component components/header import { Component, OnInit ...