OrderController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 思维定制
  5. * Date: 2018/9/5
  6. * Time: 18:03
  7. */
  8. namespace App\Http\Controllers\Web;
  9. use Illuminate\Support\Facades\Cache;
  10. use App\Models\MedicalSmsConfModel;
  11. use Illuminate\Http\Request;
  12. class OrderController extends Controller
  13. {
  14. public function index(Request $request){
  15. if($request->method() == 'POST') {
  16. $data = $request->input();
  17. $code = Cache::get($data['mobile'].'post');
  18. }
  19. return view('web.order.index');
  20. }
  21. public function post(){
  22. return view('web.order.post');
  23. }
  24. /**
  25. ***聚合数据
  26. ***DATE:2015-05-25
  27. */
  28. public function smsJuHe(Request $request)
  29. {
  30. $data = $request->input();
  31. $conf = MedicalSmsConfModel::find(1);
  32. header('content-type:text/html;charset=utf-8');
  33. $sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
  34. $num = rand(1000,9999);
  35. Cache::put($data['mobile'].'post',$num,10000);
  36. $smsConf = array(
  37. 'key' => $conf->apikey, //您申请的APPKEY
  38. 'mobile' => $data['mobile'], //接受短信的用户手机号码
  39. 'tpl_id' => $conf->temp_id, //您申请的短信模板ID,根据实际情况修改
  40. 'tpl_value' =>'#code#=1234&#company#='.$conf->sign //您设置的模板变量,根据实际情况修改
  41. );
  42. $content = $this->juhecurl($sendUrl,$smsConf,1); //请求发送短信
  43. //$content=false;
  44. if($content){
  45. $result = json_decode($content,true);
  46. $error_code = $result['error_code'];
  47. if($error_code == 0){
  48. //状态为0,说明短信发送成功
  49. $res['state'] = 1;
  50. }else{
  51. //状态非0,说明失败
  52. $msg = $result['reason'];
  53. $res['err'] = "短信发送失败(".$error_code."):".$msg;
  54. $res['state'] = 0;
  55. }
  56. }else{
  57. $res['state'] = 0;
  58. $res['err'] = '发送失败';
  59. }
  60. return $this->api($res);
  61. }
  62. /**
  63. * 请求接口返回内容
  64. * @param string $url [请求的URL地址]
  65. * @param string $params [请求的参数]
  66. * @param int $ipost [是否采用POST形式]
  67. * @return string
  68. */
  69. function juhecurl($url,$params=false,$ispost=0){
  70. $httpInfo = array();
  71. $ch = curl_init();
  72. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  73. curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
  74. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
  75. curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
  76. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  77. if( $ispost )
  78. {
  79. curl_setopt( $ch , CURLOPT_POST , true );
  80. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  81. curl_setopt( $ch , CURLOPT_URL , $url );
  82. }
  83. else
  84. {
  85. if($params){
  86. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  87. }else{
  88. curl_setopt( $ch , CURLOPT_URL , $url);
  89. }
  90. }
  91. $response = curl_exec( $ch );
  92. if ($response === FALSE) {
  93. //echo "cURL Error: " . curl_error($ch);
  94. return false;
  95. }
  96. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  97. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  98. curl_close( $ch );
  99. return $response;
  100. }
  101. }