<?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. MAC OS系统替换homebrew使用阿里云的镜像源

    MAC OS系统替换homebrew使用阿里云的镜像源 2019-03-03 15:13:42 南通SEO 阅读数 2024更多 分类专栏: 解决方案   MAC OS系统替换homebrew使用阿里 ...

  2. TensorFlow(五):手写数字识别加强版

    # 该版本的最终识别准确率达到98%以上 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_d ...

  3. TensorFlow(十四):谷歌图像识别网络inception-v3下载与查看结构

    上代码: import tensorflow as tf import os import tarfile import requests #inception模型下载地址 inception_pre ...

  4. python 最小二乘 leastsq 函数实现

    代码修改自 http://www.cnblogs.com/NanShan2016/p/5493429.html 网上百度了一下,主要是两个例子,一个利用了多项式函数,一个就是这个.有些细节没看懂,主要 ...

  5. 使用MockMVC与Junit进行单体测试

    1.pom.xml追加 junit spring-test 2.测试共通类 @ContextConfiguration(locations = { "classpath:springfram ...

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

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

  7. Java并发编程示例代码-----ReentrantLock

    public class ReenterLock implements Runnable{ public static ReentrantLock lock=new ReentrantLock(); ...

  8. C语言应用--数据类型定制一结构体数组

    结构体定义成功后,其实和c语言内部的类型区别也不大了,自然可以用来定义结构体类型的数组了.我们根据结构体定义的方式不同,分别用多种方式定义结构体数组:

  9. scanf和fgets比较

    scanf 长度限制 #include<stdio.h> int main() { char food[5]; printf("Enter food"); scanf( ...

  10. Alpha冲刺(3/4)

    队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11899921.html 作业博客 :https://edu.cnblogs.com/campus/f ...