123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App\Support\Code;
- use Illuminate\Support\Facades\DB;
- define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
- define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
- define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
- define("YP_TPLS_URL", "https://sms.yunpian.com/v2/sms/tpl_batch_send.json");
- // define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/single_send.json");
- class Ypsms implements \App\Support\Contracts\Code
- {
- /**
- * [sendCodes 短信群发]
- * @Author mzb
- * @DateTime 2018-11-09T16:09:35+0800
- * @param [type] $tplId [description]
- * @param [type] $mobiles [description]
- * @param [type] $parameter [description]
- * @return [type] [description]
- */
- public static function sendCodes($tplId, $mobiles, $parameter)
- {
- $parameter = json_decode($parameter, true);
- $arr = [];
- foreach ($parameter as $k => $p) {
- $arr[] = '#' . $k . '#=' . urlencode($p);
- }
- $str = implode('&', $arr);
- $data = array('tpl_id' => $tplId, 'tpl_value' => $str, 'apikey' => YP_SMS_KEY, 'mobile' => $mobiles);
- // return self::tplSend($data);
- $result = curlInit(YP_TPLS_URL, $data, 'Post');
- if ($result !== false) {
- $result = json_decode($result, true);
- /*liujuan 错误原因*/
- $reason="";
- if (isset($result['data'][0]['msg'])) {
- $reason=$result['data'][0]['msg'];
- }
-
- if (isset($result['total_fee'])) {
- /*liujuan total_fee>0.0000才是发送成功*/
- if ($result['total_fee']>0.0000) {
- $result['IS_SUCCESS'] = 1;
- }else{
- $result['IS_SUCCESS'] = 0;
- $result['reason']=$reason;
- }
- //原版 $result['IS_SUCCESS'] = 1;
- } else {
- $result['IS_SUCCESS'] = 0;
- /*liujuan 报错原因*/
- $result['reason']="服务端错误";
- }
- }
- return $result;
- }
- /**
- * [sendBillCode 钱多多发送验证码接口]
- * @Author mzb
- * @DateTime 2018-04-02T14:07:06+0800
- * @param [type] $phone [description]
- * @param integer $type [description]
- * @return [type] [description]
- */
- public static function sendCode($tplId, $mobile, $parameter, $type = 1)
- {
- $parameter = json_decode($parameter, true);
- if ($type == 1) {
- $arr = [];
- foreach ($parameter as $k => $p) {
- $arr[] = '#' . $k . '#=' . urlencode($p);
- }
- $str = implode('&', $arr);
- $data = array('tpl_id' => $tplId, 'tpl_value' => $str, 'apikey' => YP_SMS_KEY, 'mobile' => $mobile);
- // return self::tplSend($data);
- $result = curlInit(YP_TPL_URL, $data, 'Post');
- } else if ($type == 2) {
- if (!isset($parameter['code'])) {
- return false;
- }
- $code = $parameter['code'];
- $data = array('code' => $code, 'apikey' => YP_SMS_KEY, 'mobile' => $mobile);
- $result = curlInit(YP_VOICE_URL, $data, 'Post');
- }
- if ($result == false) {
- return false;
- }
- $result = json_decode($result, true);
- if (isset($result['fee'])) {
- $result['IS_SUCCESS'] = 1;
- } else {
- $result['IS_SUCCESS'] = 0;
- $result['reason']="服务端错误";
- }
- return $result;
- }
- }
|