作者 潘浩文
1 个管道 的构建 通过 耗费 2 秒

个人中心接口

... ... @@ -8,12 +8,14 @@ namespace api\portal\controller;
use cmf\controller\RestBaseController;
use think\Db;
/**
* @title 我的
* @description 个人中心相关接口
*/
class UserController extends RestBaseController
{
/**
* @title 我的健康档案
* @description 健康档案页渲染
... ... @@ -52,7 +54,40 @@ class UserController extends RestBaseController
public function registerPost(){
$param=$this->request->param();
$param['status']=1;
Db::name('user')->where('id')->update($param);
Db::name('user')->where('id',$this->getUserId())->update($param);
$this->success('提交成功');
}
/**
* @title 手机号注册
* @description 手机号注册提交接口
* @author panhaowen
* @url /portal/User/mobile
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @param name:mobile require:1
*/
public function mobile(){
$param=$this->request->param();
Db::name('user')->where('id',$this->getUserId())->update(['mobile'=>$param['mobile']]);
$this->success('注册提交成功');
}
/**
* @title 获取验证码
* @description 获取验证码接口
* @author panhaowen
* @url /portal/User/getCode
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @param name:mobile require:1
*/
public function getCode(){
$param=$this->request->param();
require_once VENDOR_PATH . "sms/serverSid.php";
require_once VENDOR_PATH . "sms/lib/Ucpaas.class.php";
$send=new \Ucpaas();
$code = cmf_get_verification_code($param['mobile'], 4);
$send->SendSms('78950d10e37b4ae5bd9b9c08f3720db3','41494',$code,17694933850);
}
}
... ...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<title>云之讯 - 验证短信测试Demo</title>
<script type="text/javascript" src="uc/jquery-easyui-1.4.5/jquery.min.js"></script>
</head>
<body style="background-color:#48c690">
<br>
<p style="text-align:center"><b>测试短信验证码</b></p>
<p style="text-align:center;color:#FF0000">测试前,请先阅读《请先读我(重要).doc》并配置好相应参数,<a href="http://docs.ucpaas.com/doku.php?id=error_code" target="black">点击查看错误码</a></p>
<div style="margin:0 auto;width:350px;height:150px">
<form id="myForm" action="smsyzm.php" method="post">
<table>
<tr>
<td>接收短信的手机号: </td>
<td><input type="text" name="yzmtel" size="20" style="margin-right:0px"> </td>
</tr>
<tr>
<td>验证码: </td>
<td><input type="text" name="yzm" size="20" style="margin-right:0px"></td>
</tr>
<tr>
<td><a href="#" onclick="document.getElementById('myForm').submit();"></td>
<td><input type="submit" value="提交测试" style="margin-left: 0px;width:100px;"/></td>
</tr>
</table>
</form>
</div>
</body>
</html>
\ No newline at end of file
... ...
<?php
/**
* Created by Notepad++
* User: UCPAAS NickLuo
* Date: 2017/11/09
* Time: 08:28
* Dec : ucpass php sdk
*/
class Ucpaas
{
//API请求地址
const BaseUrl = "https://open.ucpaas.com/ol/sms/";
//开发者账号ID。由32个英文字母和阿拉伯数字组成的开发者账号唯一标识符。
private $accountSid;
//开发者账号TOKEN
private $token;
public function __construct($options)
{
if (is_array($options) && !empty($options)) {
$this->accountSid = isset($options['accountsid']) ? $options['accountsid'] : '';
$this->token = isset($options['token']) ? $options['token'] : '';
} else {
throw new Exception("非法参数");
}
}
private function getResult($url, $body = null, $method)
{
$data = $this->connection($url,$body,$method);
if (isset($data) && !empty($data)) {
$result = $data;
} else {
$result = '没有返回数据';
}
return $result;
}
/**
* @param $url 请求链接
* @param $body post数据
* @param $method post或get
* @return mixed|string
*/
private function connection($url, $body,$method)
{
if (function_exists("curl_init")) {
$header = array(
'Accept:application/json',
'Content-Type:application/json;charset=utf-8',
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if($method == 'post'){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$body);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
curl_close($ch);
} else {
$opts = array();
$opts['http'] = array();
$headers = array(
"method" => strtoupper($method),
);
$headers[]= 'Accept:application/json';
$headers['header'] = array();
$headers['header'][]= 'Content-Type:application/json;charset=utf-8';
if(!empty($body)) {
$headers['header'][]= 'Content-Length:'.strlen($body);
$headers['content']= $body;
}
$opts['http'] = $headers;
$result = file_get_contents($url, false, stream_context_create($opts));
}
return $result;
}
/**
单条发送短信的function,适用于注册/找回密码/认证/操作提醒等单个用户单条短信的发送场景
* @param $appid 应用ID
* @param $mobile 接收短信的手机号码
* @param $templateid 短信模板,可在后台短信产品→选择接入的应用→短信模板-模板ID,查看该模板ID
* @param null $param 变量参数,多个参数使用英文逗号隔开(如:param=“a,b,c”)
* @param $uid 用于贵司标识短信的参数,按需选填。
* @return mixed|string
* @throws Exception
*/
public function SendSms($appid,$templateid,$param=null,$mobile,$uid){
$url = self::BaseUrl . 'sendsms';
$body_json = array(
'sid'=>$this->accountSid,
'token'=>$this->token,
'appid'=>$appid,
'templateid'=>$templateid,
'param'=>$param,
'mobile'=>$mobile,
'uid'=>$uid,
);
$body = json_encode($body_json);
$data = $this->getResult($url, $body,'post');
return $data;
}
/**
群发送短信的function,适用于运营/告警/批量通知等多用户的发送场景
* @param $appid 应用ID
* @param $mobileList 接收短信的手机号码,多个号码将用英文逗号隔开,如“18088888888,15055555555,13100000000”
* @param $templateid 短信模板,可在后台短信产品→选择接入的应用→短信模板-模板ID,查看该模板ID
* @param null $param 变量参数,多个参数使用英文逗号隔开(如:param=“a,b,c”)
* @param $uid 用于贵司标识短信的参数,按需选填。
* @return mixed|string
* @throws Exception
*/
public function SendSms_Batch($appid,$templateid,$param=null,$mobileList,$uid){
$url = self::BaseUrl . 'sendsms_batch';
$body_json = array(
'sid'=>$this->accountSid,
'token'=>$this->token,
'appid'=>$appid,
'templateid'=>$templateid,
'param'=>$param,
'mobile'=>$mobileList,
'uid'=>$uid,
);
$body = json_encode($body_json);
$data = $this->getResult($url, $body,'post');
return $data;
}
}
\ No newline at end of file
... ...
<?php
//载入ucpass类
require_once('lib/Ucpaas.class.php');
//初始化必填
//填写在开发者控制台首页上的Account Sid
$options['accountsid']='d63e23ab657c95babad1681133dbabdc';
//填写在开发者控制台首页上的Auth Token
$options['token']='1fc7377f48edb5bf1659284210f16418';
//初始化 $options必填
$ucpass = new Ucpaas($options);
\ No newline at end of file
... ...
<?php
//载入ucpass类
require_once('lib/Ucpaas.class.php');
require_once('serverSid.php');
$appid = "78950d10e37b4ae5bd9b9c08f3720db3"; //应用的ID,可在开发者控制台内的短信产品下查看
$templateid = "41494"; //可在后台短信产品→选择接入的应用→短信模板-模板ID,查看该模板ID
$param = $_POST['yzm']; //多个参数使用英文逗号隔开(如:param=“a,b,c”),如为参数则留空
$mobile = $_POST['yzmtel'];
$uid = "";
//70字内(含70字)计一条,超过70字,按67字/条计费,超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。
echo $ucpass->SendSms($appid,$templateid,$param,$mobile,$uid);
... ...