CommonController.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-9-23
  6. * Time: 上午11:26
  7. */
  8. namespace App\Http\Controllers\Api\V2;
  9. use App\Http\Controllers\Controller;
  10. use App\Models\Article;
  11. use App\Models\Order;
  12. use App\Models\User;
  13. use App\Models\Docter;
  14. use EasyWeChat\Factory;
  15. use http\Env\Request;
  16. use Illuminate\Support\Facades\DB;
  17. use AlibabaCloud\Client\Exception\ClientException;
  18. use Alibabaloud\Client\Exception\ServerException;
  19. use AlibabaCloud\Client\AlibabaCloud;
  20. use AlibabaCloud\Dybaseapi\MNS\Requests\BatchReceiveMessage;
  21. use AlibabaCloud\Dybaseapi\MNS\Requests\BatchDeleteMessage;
  22. use App\Models\CallLog;
  23. use App\Models\Axb;
  24. use App\Models\ImMessage;
  25. use Cache;
  26. /**
  27. * 公共方法类
  28. * Class CommonController
  29. * @package App\Http\Controllers\Api\V2
  30. */
  31. class CommonController extends Controller
  32. {
  33. public function wxLogin()
  34. {
  35. $req = request()->post();
  36. $this->validate(request(), [
  37. 'wechat_code' => 'required',
  38. 'nickname|昵称' => 'max:50',
  39. 'phone|手机号' => 'max:20',
  40. 'avatar|头像' => 'url',
  41. 'latitude|纬度' => 'numeric',
  42. 'longitude|纬度' => 'numeric',
  43. ]);
  44. $app = Factory::miniProgram(config('config.docter_wechat_small_program'));
  45. $data = $app->auth->session($req['wechat_code']);
  46. if (empty($data['openid'])) {
  47. return out(null, 10001, '微信登录code错误');
  48. }
  49. $session_key = !empty($data['session_key']) ? $data['session_key'] : '';
  50. $user = Docter::select(['id', 'status', 'phone', 'name', 'avatar'])->where('openid', $data['openid'])->first();
  51. if (empty($user)) {
  52. $docter_list = [
  53. 'type' => 1,
  54. 'openid' => $data['openid'],
  55. 'session_key' => $session_key,
  56. 'phone' => $req['phone'],
  57. 'sex' => 0,
  58. 'birthday' => 0,
  59. 'status' => 1,
  60. 'label' => '无',
  61. 'sign' => '无',
  62. 'intro' => 0,
  63. 'office_id' => 0,
  64. 'qualification_id' => 0,
  65. 'score' => 0,
  66. 'service_persons' => 0,
  67. 'eva_num' => 0,
  68. 'service_days' => 0,
  69. 'phone_minutes' => 0,
  70. 'chat_price' => 0,
  71. 'phone_price' => 0,
  72. 'appoint_price' => 0,
  73. 'is_chat' => 0,
  74. 'is_phone' => 0,
  75. 'is_appoint' => 0,
  76. 'latitude' => $req['latitude'] ?? 0,
  77. 'longitude' => $req['longitude'] ?? 0,
  78. 'is_then' => 0,
  79. 'practice' => 0,
  80. 'card_photo' => 0,
  81. 'is_quail' => 0,
  82. 'card_id' => 0,
  83. ];
  84. $docter_list['name'] = $req['nickname'] ?? '';
  85. $docter_list['avatar'] = $req['avatar'] ?? request()->getScheme() . '://' . request()->getHost() . '/img/default-head.png';
  86. $user = Docter::create($docter_list);
  87. if (empty($docter_list['name'])) {
  88. $nickname = '用户' . base_convert($user['id'], 10, 16);
  89. Docter::where('id', $user['id'])->update(['name' => $nickname]);
  90. }
  91. } else {
  92. if ($user['status'] == 0) {
  93. return out(null, 10002, '该账号已被冻结');
  94. }
  95. Docter::where('id', $user['id'])->update([
  96. 'name' => $req['nickname'] ?? '',
  97. 'avatar' => $req['avatar'] ?? '',
  98. 'latitude' => $req['latitude'] ?? 0,
  99. 'longitude' => $req['longitude'] ?? 0,
  100. 'phone' => $req['phone'] ?? 0,
  101. 'session_key' => $session_key
  102. ]);
  103. }
  104. $token = aes_encrypt(['doctor_id' => $user['id'], 'time' => time()]);
  105. $datas = [
  106. 'avatar' => $user['avatar'],
  107. 'name' => $user['name'],
  108. 'flag' => 'doctor_' . $user['id'],
  109. ];
  110. return out(['token' => $token, 'data' => $datas]);
  111. }
  112. /**
  113. * 获取手机号!
  114. * Auth:Yuanhang-Liu
  115. * Date:2020/10/18 17:17 *
  116. * @return \Illuminate\Http\JsonResponse
  117. */
  118. public function getPhoneNumber()
  119. {
  120. $req = request()->post();
  121. $this->validate(request(), [
  122. 'wechat_code' => 'required',
  123. 'iv' => 'required',
  124. 'encryptedData' => 'required',
  125. ]);
  126. $app = Factory::miniProgram(config('config.docter_wechat_small_program'));
  127. $data = $app->auth->session($req['wechat_code']);
  128. if (empty($data['openid']) || empty($data['session_key'])) {
  129. return out(null, 10001, '微信code错误');
  130. }
  131. $session_key = $data['session_key'];
  132. $decryptedData = $app->encryptor->decryptData($session_key, $req['iv'], $req['encryptedData']);
  133. if (!isset($decryptedData['phoneNumber']) || empty($decryptedData['phoneNumber'])) {
  134. return out(['status' => false, 'msg' => '手机号解密失败!']);
  135. }
  136. $docter_list = [
  137. 'type' => 1,
  138. 'openid' => $data['openid'],
  139. 'session_key' => $session_key,
  140. 'name' => '',
  141. 'phone' => $decryptedData['phoneNumber'],
  142. 'sex' => 0,
  143. 'birthday' => 0,
  144. 'avatar' => request()->getScheme() . '://' . request()->getHost() . '/img/default-head.png',
  145. 'status' => 1,
  146. 'label' => '无',
  147. 'sign' => '无',
  148. 'intro' => 0,
  149. 'office_id' => 0,
  150. 'qualification_id' => 0,
  151. 'score' => 0,
  152. 'service_persons' => 0,
  153. 'eva_num' => 0,
  154. 'service_days' => 0,
  155. 'phone_minutes' => 0,
  156. 'chat_price' => 0,
  157. 'phone_price' => 0,
  158. 'appoint_price' => 0,
  159. 'is_chat' => 0,
  160. 'is_phone' => 0,
  161. 'is_appoint' => 0,
  162. 'latitude' => 0,
  163. 'longitude' => 0,
  164. 'is_then' => 0,
  165. 'practice' => 0,
  166. 'card_photo' => 0,
  167. 'is_quail' => 0,
  168. 'card_id' => 0,
  169. ];
  170. // 查询医生表有没有记录
  171. $find = Docter::where('phone', $decryptedData['phoneNumber'])->first();
  172. if (!$find) {
  173. $user = Docter::create($docter_list);
  174. $nickname = '医生' . base_convert($user['id'], 10, 16);
  175. Docter::where('id', $user['id'])->update(['name' => $nickname]);
  176. }else{
  177. Docter::where('id', $find['id'])->update(['openid' => $data['openid'],'session_key'=>$session_key]);
  178. }
  179. return out($decryptedData);
  180. }
  181. /**
  182. * 手机号登陆
  183. * Auth:Yuanhang-Liu
  184. * Date:2020/10/18 19:17 *
  185. * @return \Illuminate\Http\JsonResponse
  186. */
  187. public function phoneLogin(){
  188. $req = request()->post();
  189. $this->validate(request(), [
  190. 'phone|手机号' => 'required|integer',
  191. 'verify|验证码' => 'required|integer',
  192. ]);
  193. $verify = (int)$req['verify'];
  194. $verifyCode = Cache::get($req['phone'].'-', $verify, config('config.aly_sms.sms_verify_code_expire'));
  195. if ($verifyCode!=$verify){
  196. return out('',401,'验证码错误!');
  197. }
  198. $find = Docter::where('phone','=',$req['phone'])->first();
  199. if (empty($find)){
  200. $docter_list = [
  201. 'type' => 1,
  202. 'name' => '医生' . base_convert($find['id'], 10, 16),
  203. 'phone' => $req['phone'],
  204. 'sex' => 0,
  205. 'birthday' => 0,
  206. 'avatar' => '../../static/login/moren.png',
  207. 'status' => 1,
  208. 'label' => '无',
  209. 'sign' => '无',
  210. 'intro' => 0,
  211. 'office_id' => 0,
  212. 'qualification_id' => 0,
  213. 'score' => 0,
  214. 'service_persons' => 0,
  215. 'eva_num' => 0,
  216. 'service_days' => 0,
  217. 'phone_minutes' => 0,
  218. 'chat_price' => 0,
  219. 'phone_price' => 0,
  220. 'appoint_price' => 0,
  221. 'is_chat' => 0,
  222. 'is_phone' => 0,
  223. 'is_appoint' => 0,
  224. 'latitude' => 0,
  225. 'longitude' => 0,
  226. 'is_then' => 0,
  227. 'practice' => 0,
  228. 'card_photo' => 0,
  229. 'is_quail' => 0,
  230. 'card_id' => 0,
  231. ];
  232. $list = Docter::create($docter_list)->toArray();
  233. if (!empty($list)){
  234. $datas = [
  235. 'avatar' => $list['avatar'],
  236. 'name' => $list['name'],
  237. 'flag' => 'doctor_'.$list['id'],
  238. ];
  239. $token = aes_encrypt(['doctor_id' => $list['id'], 'time' => time()]);
  240. return out(['token' => $token,'data'=>$datas]);
  241. }else{
  242. return out('',401,'用户不存在,注册失败!');
  243. }
  244. }
  245. $find = $find->toArray();
  246. if ($find['status'] == 0) {
  247. return out(null, 10002, '该账号已被冻结');
  248. }
  249. $datas = [
  250. 'avatar' => $find['avatar'],
  251. 'name' => $find['name'],
  252. 'flag' => 'doctor_'.$find['id'],
  253. ];
  254. // 验证是否正确
  255. $token = aes_encrypt(['doctor_id' => $find['id'], 'time' => time()]);
  256. Cache::delete($req['phone'] . '-', $verify);
  257. return out(['token' => $token,'data'=>$datas]);
  258. }
  259. /**
  260. * 账号密码登陆
  261. * Auth:Yuanhang-Liu
  262. * Date:2020/10/18 19:17 *
  263. * @return \Illuminate\Http\JsonResponse
  264. */
  265. public function passLogin(){
  266. $req = request()->post();
  267. $this->validate(request(), [
  268. 'phone|手机号' => 'required|integer',
  269. 'password|密码' => 'required',
  270. ]);
  271. $find = Docter::where('phone','=',$req['phone'])->first();
  272. if (empty($find)){
  273. return out(null, 401, '账号不存在');
  274. }
  275. if ($find['status'] == 0) {
  276. return out(null, 10002, '该账号已被冻结');
  277. }
  278. $find = $find->toArray();
  279. // 验证密码
  280. $password = md5(md5(md5($req['password'])));
  281. if ($password==$find['password']){
  282. $datas = [
  283. 'avatar' => $find['avatar'],
  284. 'name' => $find['name'],
  285. 'flag' => 'doctor_'.$find['id'],
  286. ];
  287. $token = aes_encrypt(['doctor_id' => $find['id'], 'time' => time()]);
  288. return out(['token' => $token,'data'=>$datas]);
  289. }else{
  290. return out(null, 401, '密码错误');
  291. }
  292. }
  293. /**
  294. * 获取验证码
  295. * @return \Illuminate\Http\JsonResponse
  296. * @author Liu-Yh
  297. * Create By 2020/11/6 10:45
  298. */
  299. public function putverfiy(){
  300. //防止恶意刷验证码接口,一分钟最多10次
  301. check_repeat_request(60, 10);
  302. $req = request()->post();
  303. $this->validate(request(), [
  304. 'phone|手机号' => 'required|integer',
  305. ]);
  306. $mobile =$req['phone']; //获取传入的手机号
  307. $verify_code = generate_code();
  308. $result = send_sms($mobile,'verify_template_code',['code'=>$verify_code]);
  309. if (empty($result['Code']) || $result['Code'] != 'OK'){
  310. return out(null, 30010, '验证码发送失败,请稍后重试');
  311. }
  312. Cache::set($req['phone'].'-', $verify_code, config('config.aly_sms.sms_verify_code_expire'));
  313. return out();
  314. }
  315. /**
  316. * 手机号注册
  317. * Auth:Yuanhang-Liu
  318. * Date:2020/10/18 20:17 *
  319. * @return \Illuminate\Http\JsonResponse
  320. */
  321. public function phoneRegister(){
  322. $req = request()->post();
  323. $this->validate(request(), [
  324. 'phone|手机号' => 'required|integer',
  325. 'password|密码' => 'required',
  326. 'verify|验证码' => 'required|integer',
  327. ]);
  328. $verify = (int)$req['verify'];
  329. $verifyCode = Cache::get($req['phone'].'-', $verify, config('config.aly_sms.sms_verify_code_expire'));
  330. if ($verifyCode!=$verify){
  331. return out('',401,'验证码错误!');
  332. }
  333. // 查询是否注册过!
  334. $docters = Docter::where('phone','=',$req['phone'])->first();
  335. if (!empty($docters)){
  336. return out('',500,'此手机号已被注册!');
  337. }
  338. $password = md5(md5(md5($req['password'])));
  339. $docter_list = [
  340. 'type' => 1,
  341. 'name' => '用户名',
  342. 'phone' => $req['phone'],
  343. 'sex' => 0,
  344. 'birthday' => 0,
  345. 'avatar' => '无',
  346. 'status' => 1,
  347. 'label' => '无',
  348. 'sign' => '',
  349. 'intro' => '',
  350. 'office_id' => 0,
  351. 'qualification_id' => 0,
  352. 'score' => 0,
  353. 'service_persons' => 0,
  354. 'eva_num' => 0,
  355. 'service_days' => 0,
  356. 'phone_minutes' => 0,
  357. 'chat_price' => 0,
  358. 'phone_price' => 0,
  359. 'appoint_price' => 0,
  360. 'is_chat' => 0,
  361. 'is_phone' => 0,
  362. 'is_appoint' => 0,
  363. 'latitude' => 0,
  364. 'longitude' => 0,
  365. 'password' => $password,
  366. 'is_then' => 0,
  367. 'practice' => 0,
  368. 'card_photo' => 0,
  369. 'is_quail' => 0,
  370. 'card_id' => 0,
  371. ];
  372. $list = Docter::create($docter_list)->toArray();
  373. if (!empty($list)){
  374. $datas = [
  375. 'avatar' => $list['avatar'],
  376. 'name' => $list['name'],
  377. 'flag' => 'doctor_'.$list['id'],
  378. ];
  379. $token = aes_encrypt(['doctor_id' => $list['id'], 'time' => time()]);
  380. return out(['token' => $token,'data'=>$datas]);
  381. }else{
  382. return out('',500,'注册失败!');
  383. }
  384. // return out();
  385. }
  386. public function articleList()
  387. {
  388. $data = Article::orderBy('id', 'desc')->paginate();
  389. return out($data);
  390. }
  391. public function getUserIdByDoctorId($phone=null){
  392. $list = Docter::where('phone', $phone)->first();
  393. if ($list){
  394. return $list->id;
  395. }else{
  396. return false;
  397. }
  398. }
  399. public function uploadFile()
  400. {
  401. $file = request()->file('file');
  402. if (empty($file)) {
  403. return out(null, 10001, '文件不能为空');
  404. }
  405. $path = $file->store('upload/docter/'.date('Ymd'));
  406. // $url = request()->getScheme().'://'.request()->getHost().'/'.$path;
  407. return out(['url' => $path]);
  408. }
  409. public function doc()
  410. {
  411. $database = env('DB_DATABASE');
  412. $prefix = env('DB_PREFIX');
  413. $exclude_tables = "'bm_password_resets','bm_admin_menu','bm_admin_users','bm_failed_jobs','bm_migrations'";
  414. $sql = "select TABLE_NAME name,TABLE_COMMENT comment from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='".$database."' and TABLE_NAME not in (".$exclude_tables.")";
  415. $tables = \DB::select($sql);
  416. $map1 = $map2 = [];
  417. $i = round(count($tables)/2);
  418. foreach ($tables as $k => $v) {
  419. $name = str_replace($prefix, '', $v->name);
  420. if ($k >= $i) {
  421. $map1[$v->name] = $name.'('.$v->comment.')';
  422. }
  423. else {
  424. $map2[$v->name] = $name.'('.$v->comment.')';
  425. }
  426. }
  427. $data1 = [];
  428. foreach ($map1 as $k => $v){
  429. $sql = "select COLUMN_NAME name, DATA_TYPE type, COLUMN_COMMENT comment from INFORMATION_SCHEMA.COLUMNS where table_schema = '".$database."' AND table_name = '".$k."'";
  430. $comment = \DB::select($sql);
  431. $data1[$v] = $comment;
  432. }
  433. $data2 = [];
  434. foreach ($map2 as $k => $v){
  435. $sql = "select COLUMN_NAME name, DATA_TYPE type, COLUMN_COMMENT comment from INFORMATION_SCHEMA.COLUMNS where table_schema = '".$database."' AND table_name = '".$k."'";
  436. $comment = \DB::select($sql);
  437. $data2[$v] = $comment;
  438. }
  439. return view('doc', ['data1' => $data1, 'data2' => $data2]);
  440. }
  441. /**
  442. * 绑定号码池子
  443. * @param string $phone1 医生id
  444. * @param string $phone2 用户id
  445. * @param array $data 参数
  446. * @return mixed
  447. */
  448. public function BindAxb($phone1,$phone2,$data=[]){
  449. $config = config('config.axb');
  450. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  451. ->regionId('cn-kunming')
  452. ->asDefaultClient();
  453. try {
  454. $result = AlibabaCloud::rpc()
  455. ->product('Dyplsapi')
  456. ->version('2017-05-25')
  457. ->action('BindAxb')
  458. ->method('POST')
  459. ->host('dyplsapi.aliyuncs.com')
  460. ->options([
  461. 'query' => [
  462. "Expiration" => date("Y-m-d H:i:s",strtotime("+1 day")),
  463. 'RegionId' => "cn-kunming",
  464. 'PhoneNoA' => $phone1,
  465. 'PhoneNoB' => $phone2,
  466. // 修改
  467. 'IsRecordingEnabled' => true
  468. ],
  469. ])
  470. ->request();
  471. return $result->toArray();
  472. } catch (ClientException $e) {
  473. echo $e->getErrorMessage() . PHP_EOL;
  474. } catch (ServerException $e) {
  475. echo $e->getErrorMessage() . PHP_EOL;
  476. }
  477. }
  478. /**
  479. * 释放虚拟号码
  480. * @param int $phone
  481. */
  482. public function ReleaseSecretNo($phone){
  483. $config = config('config.axb');
  484. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  485. ->regionId('cn-kunming')
  486. ->asDefaultClient();
  487. try {
  488. $result = AlibabaCloud::rpc()
  489. ->product('Dyplsapi')
  490. // ->scheme('https') // https | http
  491. ->version('2017-05-25')
  492. ->action('ReleaseSecretNo')
  493. ->method('POST')
  494. ->host('dyplsapi.aliyuncs.com')
  495. ->options([
  496. 'query' => [
  497. 'RegionId' => "cn-kunming",
  498. "SecretNo" => $phone,
  499. "PoolKey" => $config['PoolKey'],
  500. ],
  501. ])
  502. ->request();
  503. $res = $result->toArray();
  504. return $res;
  505. } catch (ClientException $e) {
  506. echo $e->getErrorMessage() . PHP_EOL;
  507. } catch (ServerException $e) {
  508. echo $e->getErrorMessage() . PHP_EOL;
  509. }
  510. }
  511. /**
  512. * 查询号码关系
  513. * @param $phone
  514. * @return mixed
  515. */
  516. public function QuerySubscriptionDetail($phone,$SubsId){
  517. $config = config('config.axb');
  518. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  519. ->regionId('cn-kunming')
  520. ->asDefaultClient();
  521. try {
  522. $result = AlibabaCloud::rpc()
  523. ->product('Dyplsapi')
  524. // ->scheme('https') // https | http
  525. ->version('2017-05-25')
  526. ->action('QuerySubscriptionDetail')
  527. ->method('POST')
  528. ->host('dyplsapi.aliyuncs.com')
  529. ->options([
  530. 'query' => [
  531. 'RegionId' => "cn-hangzhou",
  532. "PoolKey" => $config['PoolKey'],
  533. "SubsId" => $SubsId,
  534. "PhoneNoX" => $phone,
  535. ],
  536. ])
  537. ->request();
  538. $res = $result->toArray();
  539. return $res;
  540. } catch (ClientException $e) {
  541. echo $e->getErrorMessage() . PHP_EOL;
  542. } catch (ServerException $e) {
  543. echo $e->getErrorMessage() . PHP_EOL;
  544. }
  545. }
  546. /**
  547. * 解除绑定关系
  548. * @param $phone
  549. * @return mixed
  550. */
  551. public function UnbindSubscription($phone,$subId){
  552. $config = config('config.axb');
  553. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  554. ->regionId('cn-kunming')
  555. ->asDefaultClient();
  556. try {
  557. $result = AlibabaCloud::rpc()
  558. ->product('Dyplsapi')
  559. // ->scheme('https') // https | http
  560. ->version('2017-05-25')
  561. ->action('UnbindSubscription')
  562. ->method('POST')
  563. ->host('dyplsapi.aliyuncs.com')
  564. ->options([
  565. 'query' => [
  566. 'RegionId' => "cn-kunming",
  567. 'SubsId' => $subId,
  568. "SecretNo" => $phone,
  569. "PoolKey" => $config['PoolKey'],
  570. ],
  571. ])
  572. ->request();
  573. $res = $result->toArray();
  574. return $res;
  575. } catch (ClientException $e) {
  576. echo $e->getErrorMessage() . PHP_EOL;
  577. } catch (ServerException $e) {
  578. echo $e->getErrorMessage() . PHP_EOL;
  579. }
  580. }
  581. /**
  582. * 调用接口QuerySubsId查询绑定唯一标识SubsId
  583. * @param $phone X号码
  584. * @return mixed
  585. */
  586. public function QuerySubsId($phone){
  587. $config = config('config.axb');
  588. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  589. ->regionId('cn-kunming')
  590. ->asDefaultClient();
  591. try {
  592. $result = AlibabaCloud::rpc()
  593. ->product('Dyplsapi')
  594. // ->scheme('https') // https | http
  595. ->version('2017-05-25')
  596. ->action('QuerySubsId')
  597. ->method('POST')
  598. ->host('dyplsapi.aliyuncs.com')
  599. ->options([
  600. 'query' => [
  601. 'RegionId' => "cn-hangzhou",
  602. 'Action' => "QuerySubsId",
  603. "PhoneNoX" => $phone,
  604. "PoolKey" => $config['PoolKey'],
  605. ],
  606. ])
  607. ->request();
  608. $res = $result->toArray();
  609. return $res;
  610. } catch (ClientException $e) {
  611. echo $e->getErrorMessage() . PHP_EOL;
  612. } catch (ServerException $e) {
  613. echo $e->getErrorMessage() . PHP_EOL;
  614. }
  615. }
  616. /**
  617. * 解锁号码
  618. * @return \Illuminate\Http\JsonResponse
  619. * @author Liu-Yh
  620. * Create By 2020/11/25 18:36
  621. */
  622. public function unLokPhone($phone,$SubsId){
  623. $unlok = $this->UnbindSubscription($phone,$SubsId);
  624. if ($unlok['Code']!='OK'){
  625. return out($unlok);
  626. }else{
  627. return 1;
  628. }
  629. }
  630. /**
  631. * 测试解除绑定电话的方法
  632. */
  633. public function testunlockphone(){
  634. $phone = 17052201940;
  635. $sub_id = 1000027059330181;
  636. var_dump($this->unLokPhone($phone,$sub_id));
  637. }
  638. /**
  639. * 调用接口QueryCallStatus查询呼叫状态。
  640. * @param $phone
  641. * @author Liu-Yh
  642. * Create By 2020/11/26 10:51
  643. */
  644. public function QueryCallStatus($phone,$SubsId){
  645. $config = config('config.axb');
  646. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  647. ->regionId('cn-kunming')
  648. ->asDefaultClient();
  649. try {
  650. $result = AlibabaCloud::rpc()
  651. ->product('Dyplsapi')
  652. // ->scheme('https') // https | http
  653. ->version('2017-05-25')
  654. ->action('QueryCallStatus')
  655. ->method('POST')
  656. ->host('dyplsapi.aliyuncs.com')
  657. ->options([
  658. 'query' => [
  659. 'RegionId' => "cn-hangzhou",
  660. "PoolKey" => $config['PoolKey'],
  661. "SubsId" => $SubsId,
  662. ],
  663. ])
  664. ->request();
  665. $res = $result->toArray();
  666. return $res;
  667. } catch (ClientException $e) {
  668. echo $e->getErrorMessage() . PHP_EOL;
  669. } catch (ServerException $e) {
  670. echo $e->getErrorMessage() . PHP_EOL;
  671. }
  672. }
  673. /**
  674. * 接收通话发起时的通话记录报告内容,可以在呼叫发起时立即获取到通话记录信息,包括通话开始时间、主被叫号码等,便于平台进行预判处理
  675. * @author Liu-Yh
  676. * Create By 2020/11/25 14:44
  677. */
  678. public function StartSecretReport(){
  679. $config = config('config.axb');
  680. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  681. ->regionId('cn-kunming')
  682. ->asDefaultClient();
  683. $queueName = $config['StartReport']; // 队列名称
  684. $messageType = "SecretStartReport"; // 需要接收的消息类型
  685. $response = null;
  686. $token = null;
  687. $i = 0;
  688. do {
  689. try {
  690. if (null == $token || strtotime($token['ExpireTime']) - time() > 2 * 60) {
  691. $response = AlibabaCloud::rpcRequest()
  692. ->product('Dybaseapi')
  693. ->version('2017-05-25')
  694. ->action('QueryTokenForMnsQueue')
  695. ->method('POST')
  696. ->host("dybaseapi.aliyuncs.com")
  697. ->options([
  698. 'query' => [
  699. 'MessageType' => $messageType,
  700. 'QueueName' => $queueName,
  701. ],
  702. ])
  703. ->request()
  704. ->toArray();
  705. }
  706. $token = $response['MessageTokenDTO'];
  707. $mnsClient = new \AlibabaCloud\Dybaseapi\MNS\MnsClient(
  708. "http://1943695596114318.mns.cn-hangzhou.aliyuncs.com",
  709. $token['AccessKeyId'],
  710. $token['AccessKeySecret'],
  711. $token['SecurityToken']
  712. );
  713. $mnsRequest = new BatchReceiveMessage(10, 5);
  714. $mnsRequest->setQueueName($queueName);
  715. $mnsResponse = $mnsClient->sendRequest($mnsRequest);
  716. $receiptHandles = Array();
  717. foreach ($mnsResponse->Message as $message) {
  718. // 用户逻辑:
  719. // 入库
  720. // var_dump(base64_decode($message->MessageBody));
  721. // var_dump(json_decode(base64_decode($message->MessageBody),true));
  722. // $receiptHandles[] = $message->ReceiptHandle; // 加入$receiptHandles数组中的记录将会被删除
  723. $messageBody = json_decode(base64_decode($message->MessageBody),true); // base64解码后的JSON字符串
  724. echo "进来了";
  725. var_dump($messageBody);
  726. }
  727. if (count($receiptHandles) > 0) {
  728. $deleteRequest = new BatchDeleteMessage($queueName, $receiptHandles);
  729. $mnsClient->sendRequest($deleteRequest);
  730. }
  731. } catch (ClientException $e) {
  732. echo $e->getErrorMessage() . PHP_EOL;
  733. } catch (ServerException $e) {
  734. if ($e->getCode() == 404) {
  735. $i++;
  736. }
  737. echo $e->getErrorMessage() . PHP_EOL;
  738. }
  739. } while ($i < 3);
  740. }
  741. /**
  742. * 接收通话结束时的通话记录报告内容,可以在呼叫结束后获取通话记录信息,包括通话开始时间、通话结束时间、主被叫号码等,
  743. * @author Liu-Yh
  744. * Create By 2020/11/25 12:29
  745. */
  746. public function SecretPullReport(){
  747. $config = config('config.axb');
  748. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  749. ->regionId('cn-kunming')
  750. ->asDefaultClient();
  751. $queueName = $config['Report']; // 队列名称
  752. $messageType = "SecretReport"; // 需要接收的消息类型
  753. $response = null;
  754. $token = null;
  755. $i = 0;
  756. do {
  757. try {
  758. if (null == $token || strtotime($token['ExpireTime']) - time() > 2 * 60) {
  759. $response = AlibabaCloud::rpcRequest()
  760. ->product('Dybaseapi')
  761. ->version('2017-05-25')
  762. ->action('QueryTokenForMnsQueue')
  763. ->method('POST')
  764. ->host("dybaseapi.aliyuncs.com")
  765. ->options([
  766. 'query' => [
  767. 'MessageType' => $messageType,
  768. 'QueueName' => $queueName,
  769. ],
  770. ])
  771. ->request()
  772. ->toArray();
  773. }
  774. $token = $response['MessageTokenDTO'];
  775. $mnsClient = new \AlibabaCloud\Dybaseapi\MNS\MnsClient(
  776. "http://1943695596114318.mns.cn-hangzhou.aliyuncs.com",
  777. $token['AccessKeyId'],
  778. $token['AccessKeySecret'],
  779. $token['SecurityToken']
  780. );
  781. $mnsRequest = new BatchReceiveMessage(10, 5);
  782. $mnsRequest->setQueueName($queueName);
  783. $mnsResponse = $mnsClient->sendRequest($mnsRequest);
  784. $receiptHandles = Array();
  785. $getList = CallLog::get();
  786. if ($getList){
  787. $getList = $getList->toArray();
  788. }
  789. $msgs = $mnsResponse->Message;
  790. if (!is_array($msgs)){
  791. $messageBody = json_decode(base64_decode($msgs->MessageBody),true); // base64解码后的JSON字符
  792. if (count($getList)==0){
  793. CallLog::create([
  794. 'call_time'=>$messageBody['call_time'],
  795. 'ring_time'=>$messageBody['release_time'],
  796. 'release_dir'=>$messageBody['release_dir'],
  797. 'call_type'=>$messageBody['call_type'],
  798. 'aphone'=>$messageBody['phone_no'],
  799. 'bphone'=>$messageBody['peer_no'],
  800. 'call_id'=>$messageBody['call_id'],
  801. 'secret_no'=>$messageBody['secret_no'],
  802. 'sub_id'=>$messageBody['sub_id'],
  803. 'talk_time'=> strtotime($messageBody['release_time'])-strtotime($messageBody['start_time']),
  804. ]);
  805. }else{
  806. foreach ($getList as $k=>$v){
  807. if ($v['call_id']==$messageBody['call_id']){
  808. unset($messageBody);
  809. }else{
  810. CallLog::create([
  811. 'call_time'=>$messageBody['call_time'],
  812. 'ring_time'=>$messageBody['release_time'],
  813. 'release_dir'=>$messageBody['release_dir'],
  814. 'call_type'=>$messageBody['call_type'],
  815. 'aphone'=>$messageBody['phone_no'],
  816. 'bphone'=>$messageBody['peer_no'],
  817. 'call_id'=>$messageBody['call_id'],
  818. 'secret_no'=>$messageBody['secret_no'],
  819. 'sub_id'=>$messageBody['sub_id'],
  820. 'talk_time'=> strtotime($messageBody['release_time'])-strtotime($messageBody['start_time']),
  821. ]);
  822. }
  823. }
  824. }
  825. }else{
  826. foreach ($msgs as $message) {
  827. // 用户逻辑:
  828. $messageBody = json_decode(base64_decode($message->MessageBody),true); // base64解码后的JSON字符串
  829. if (count($getList)==0) {
  830. CallLog::create([
  831. 'call_time'=>$messageBody['call_time'],
  832. 'ring_time'=>$messageBody['release_time'],
  833. 'release_dir'=>$messageBody['release_dir'],
  834. 'call_type'=>$messageBody['call_type'],
  835. 'aphone'=>$messageBody['phone_no'],
  836. 'bphone'=>$messageBody['peer_no'],
  837. 'call_id'=>$messageBody['call_id'],
  838. 'secret_no'=>$messageBody['secret_no'],
  839. 'sub_id'=>$messageBody['sub_id'],
  840. 'talk_time'=> strtotime($messageBody['release_time'])-strtotime($messageBody['start_time']),
  841. ]);
  842. }else{
  843. foreach ($getList as $k=>$v){
  844. if ($v['call_id']==$messageBody['call_id']){
  845. unset($messageBody);
  846. }else{
  847. CallLog::create([
  848. 'call_time'=>$messageBody['call_time'],
  849. 'ring_time'=>$messageBody['release_time'],
  850. 'release_dir'=>$messageBody['release_dir'],
  851. 'call_type'=>$messageBody['call_type'],
  852. 'aphone'=>$messageBody['phone_no'],
  853. 'bphone'=>$messageBody['peer_no'],
  854. 'call_id'=>$messageBody['call_id'],
  855. 'secret_no'=>$messageBody['secret_no'],
  856. 'sub_id'=>$messageBody['sub_id'],
  857. 'talk_time'=> strtotime($messageBody['release_time'])-strtotime($messageBody['start_time']),
  858. ]);
  859. }
  860. }
  861. }
  862. $receiptHandles[] = $message->ReceiptHandle; // 加入$receiptHandles数组中的记录将会被删除
  863. }
  864. }
  865. if (count($receiptHandles) > 0) {
  866. $deleteRequest = new BatchDeleteMessage($queueName, $receiptHandles);
  867. $mnsClient->sendRequest($deleteRequest);
  868. }
  869. } catch (ClientException $e) {
  870. echo $e->getErrorMessage() . PHP_EOL;
  871. } catch (ServerException $e) {
  872. if ($e->getCode() == 404) {
  873. $i++;
  874. }
  875. echo $e->getErrorMessage() . PHP_EOL;
  876. }
  877. } while ($i < 3);
  878. }
  879. /**
  880. * 通话开始时候回调数据
  881. * @return false|string
  882. * 返回参数
  883. * [{
  884. "phone_no": "18831138292",
  885. "pool_key": "FC100000115024469", 对应的号池Key。
  886. "city": "昆明",
  887. "sub_id": 1000027052283144, 通话对应的三元组的绑定关系ID。
  888. "unconnected_cause": 0,
  889. "call_time": "2020-12-21 17:23:56", 主叫拨打时间。
  890. "peer_no": "15222021008", AXB中的B号码或者N号码。
  891. "called_display_no": "17052201941", 被叫显号X号码
  892. "call_id": "31343639616333323735", 唯一标识一通通话记录的ID。
  893. "partner_key": "FC100000115024469",
  894. "control_msg": "OK",
  895. "id": 1007221453890,
  896. "secret_no": "17052201941",
  897. "call_type": 0,0:主叫(phone_no打给peer_no);1:被叫(peer_no打给phone_no);2:短信发送;3:短信接收;4:呼叫拦截;5:短信收发拦截;
  898. "control_type": "CONTINUE"
  899. }]
  900. */
  901. public function SecretStartReport(){
  902. // 开始json
  903. $req = request()->post();
  904. // 首先创建记录
  905. if ($req){
  906. try {
  907. $data = [];
  908. $data['call_time'] = $req[0]['call_time'];
  909. $data['call_type'] = $req[0]['call_type'];
  910. $data['aphone'] = $req[0]['phone_no'];
  911. $data['bphone'] = $req[0]['peer_no'];
  912. $data['call_id'] = $req[0]['call_id'];
  913. $data['secret_no'] = $req[0]['called_display_no'];
  914. $data['sub_id'] = $req[0]['sub_id'];
  915. CallLog::create($data);
  916. }catch (\Exception $e){
  917. var_dump($e->getFile().$e->getLine().$e->getMessage());
  918. }catch (\PDOException $e){
  919. var_dump($e->getFile().$e->getLine().$e->getMessage());
  920. }
  921. }
  922. return json_encode(['code'=>0,'msg'=>"成功"],JSON_UNESCAPED_UNICODE);
  923. }
  924. /**
  925. * 电话挂断时候回调数据!
  926. * @return false|string
  927. * 回调数据
  928. * [{
  929. "phone_no": "18831138292", 主叫号码
  930. "pool_key": "FC100000115024469", 对应的号池Key。
  931. "city": "昆明",
  932. "sub_id": 1000027052283144, 通话对应的三元组的绑定关系ID。
  933. "unconnected_cause": 0, 0表示正常通话,1表示黑名单拦截,2表示无绑定关系,3表示呼叫限制,4表示其他
  934. "call_time": "2020-12-21 17:23:56", 主叫拨打时间
  935. "call_out_time": "2020-12-21 17:23:56", 呼叫由X送给B端局的时间
  936. "peer_no": "15222021008", AXB中的B号码或者N号码
  937. "called_display_no": "17052201941", 被叫显号
  938. "release_dir": 2, 通话释放方向。0表示平台释放,1表示主叫挂断,2表示被叫挂断
  939. "ring_time": "2020-12-21 17:23:56", 呼叫送被叫端局时,被叫端局响应的时间。
  940. "call_id": "31343639616333323735", 唯一标识一通通话记录的ID。
  941. "start_time": "2020-12-21 17:24:05", 被叫接听时间
  942. "free_ring_time": "2020-12-21 17:24:03",被叫手机真实的振铃时间。free_ring_time 大于call_out_time表示被叫真实发生了振铃事件。free_ring_time 和call_out_time相等表示未振铃。
  943. "partner_key": "FC100000115024469",
  944. "control_msg": "OK",
  945. "id": 1007221453890,
  946. "secret_no": "17052201941", AXB中的X号码
  947. "call_type": 0, 呼叫类型,包括:0:主叫,即phone_no打给peer_no。1:被叫,即peer_no打给phone_no。2:短信发送。3:短信接收。4:呼叫拦截5:短信收发拦截
  948. "release_cause": 16, 释放原因。请根据编号在释放原因中查看。
  949. "control_type": "CONTINUE",
  950. "release_time": "2020-12-21 17:24:09" 被叫挂断时间。release_time和start_time之差表示通话时长, 如果结果为0,说明呼叫未接通
  951. }]
  952. *
  953. */
  954. public function SecretReport(){
  955. $req = request()->post();
  956. $callids = CallLog::where('call_id',$req[0]['call_id'])->first();
  957. if ($req && $callids) {
  958. try {
  959. if ($callids){
  960. if($req[0]['release_dir']==0||(strtotime($req[0]['release_time'])-strtotime($req[0]['start_time']))==0||$req[0]['unconnected_cause']!=0){
  961. CallLog::where('call_id',$req[0]['call_id'])->delete();
  962. }else{
  963. // 修改信息
  964. $axbId = Axb::where(['xphone'=>$req[0]['called_display_no'],'subs_id'=>$req[0]['sub_id']])->first();
  965. if($axbId){
  966. $where['docter_id'] = $axbId['docter_id'];
  967. $where['user_id'] = $axbId['user_id'];
  968. $where['product_type'] =1;
  969. $where['order_status'] =3;
  970. $where['payment_status'] =2;
  971. $order_id = Order::where($where)->first();
  972. if ($order_id){
  973. $order_id = $order_id->id;
  974. $save_data = [];
  975. $save_data['order_id'] = $order_id;
  976. $save_data['ring_time'] = $req[0]['release_time'];
  977. $save_data['docter_id'] = $axbId['docter_id'];
  978. $save_data['release_dir'] = $req[0]['release_dir'];
  979. $save_data['talk_time'] = strtotime($req[0]['release_time'])-strtotime($req[0]['start_time']);
  980. $save_data['text'] = json_encode($req,JSON_UNESCAPED_UNICODE);
  981. // 解除号码绑定,并且删除数据库绑定信息
  982. // $this->unLokPhone($req[0]['called_display_no'],$req[0]['sub_id']);
  983. // Axb::where(['subs_id'=>$req[0]['sub_id']])->delete();
  984. CallLog::where('call_id',$req[0]['call_id'])->update($save_data);
  985. return json_encode(['code'=>0,'msg'=>"成功"],JSON_UNESCAPED_UNICODE);
  986. }
  987. }
  988. }
  989. }
  990. }catch (\Exception $e){
  991. CallLog::create(['text'=>json_encode($e->getFile().$e->getCode().$e->getMessage(),JSON_UNESCAPED_UNICODE)]);
  992. }catch (\PDOException $e){
  993. CallLog::create(['text'=>json_encode($e->getFile().$e->getCode().$e->getMessage(),JSON_UNESCAPED_UNICODE)]);
  994. }
  995. }
  996. return json_encode(['code' => 0, 'msg' => "成功"], JSON_UNESCAPED_UNICODE);
  997. }
  998. /**
  999. * 录音文件返回
  1000. * @return false|string
  1001. */
  1002. public function Recording_status(){
  1003. $req = request()->post();
  1004. trace(['录音文件返回'=>'成功','入库数据'=>$req[0]],'info');
  1005. $config = config('config.axb');
  1006. AlibabaCloud::accessKeyClient($config['appid'], $config['appscret'])
  1007. ->regionId('cn-kunming')
  1008. ->asDefaultClient();
  1009. try {
  1010. $result = AlibabaCloud::dyplsapi()
  1011. ->v20170525()
  1012. ->queryRecordFileDownloadUrl()
  1013. ->withCallTime(date('Y-m-d H:i:s',substr($req[0]['call_time'], 0, 10)))
  1014. ->withCallId($req[0]['call_id'])
  1015. ->withPoolKey($req[0]['pool_key'])
  1016. ->request()->toArray();
  1017. trace(['录音文件返回1'=>'成功1','入库数据'=>$result],'info');
  1018. if ($result['Message']=='OK'){
  1019. $file = $this->downImgRar($result['DownloadUrl'],$req[0]['call_id']);
  1020. CallLog::where('call_id',$req[0]['call_id'])->update(['files'=>$file]);
  1021. trace(['录音文件完成'=>'成功','入库链接'=>$file],'info');
  1022. }
  1023. }catch (\Exception $e){
  1024. trace(['录音文件返回'=>'失败','入库数据'=>$req,'录音文件返回'=>isset($result)?$result:''],'info');
  1025. }
  1026. return json_encode(['code' => 0, 'msg' => "成功"], JSON_UNESCAPED_UNICODE);
  1027. }
  1028. /**
  1029. * 链接下载到本地
  1030. * @param $url
  1031. * @param $rename
  1032. * @param $ext
  1033. * @return string
  1034. */
  1035. public function downImgRar($url,$rename,$ext='mp3'){
  1036. trace(['开始转换'=>'1','链接'=>$url],'info');
  1037. try {
  1038. $dir = iconv("UTF-8", "GBK", "upload/callLog/");
  1039. if (!file_exists($dir)){
  1040. mkdir ($dir,0777,true);
  1041. }
  1042. $file_path = 'upload/callLog/';
  1043. $ch = curl_init($url);
  1044. curl_setopt($ch, CURLOPT_HEADER, 0);
  1045. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1046. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  1047. $rawdata=curl_exec ($ch);
  1048. curl_close ($ch);
  1049. // 使用中文文件名需要转码
  1050. $fp = fopen($file_path.iconv('UTF-8', 'GBK', $rename).".".$ext,'w');
  1051. fwrite($fp, $rawdata);
  1052. fclose($fp);
  1053. // 返回路径
  1054. trace(['转换成功!'=>'1','地址'=>$_SERVER['DOCUMENT_ROOT'].$file_path.$rename.".".$ext],'info');
  1055. return $file_path.$rename.".".$ext;
  1056. }catch (\Exception $e){
  1057. trace(['转换失败'=>'1','错误'=>$e->getFile().'文件'.$e->getLine().'行'.$e->getMessage().'错误!'],'info');
  1058. }
  1059. }
  1060. /**
  1061. * goEasy聊天记录存入数据库
  1062. * * @return false|string
  1063. */
  1064. public function easyMessage(){
  1065. $req = request()->post();
  1066. try {
  1067. $data = json_decode($req['content'],true);
  1068. $reminderController = new PatientController();
  1069. $list = [];
  1070. if($data){
  1071. $ImList = ImMessage::select('messageId')->groupBy('messageId')->get();
  1072. $newList=[];
  1073. if ($ImList){
  1074. foreach ($ImList as $k=>$v){
  1075. $newList[$k] = $v['messageId'];
  1076. }
  1077. }
  1078. foreach ($data as $k=>$v){
  1079. if(!in_array($v['messageId'],$newList)){
  1080. $list[$k]['messageId'] = $v['messageId'];
  1081. $list[$k]['type'] = $v['type'];
  1082. $list[$k]['senderId'] = $v['senderId'];
  1083. $list[$k]['receiverId'] = $v['receiverId'];
  1084. $list[$k]['timestamp'] = $v['timestamp'];
  1085. $list[$k]['payload'] = $v['payload'];
  1086. $list[$k]['text'] = $req['content'];
  1087. $list[$k]['create_time'] = time();
  1088. if (substr($v['senderId'],0,6)=='doctor'){
  1089. // 说明是用户给医生发的, 就给医生端发消息
  1090. $docter_id = substr($v['senderId'], 7);
  1091. $docter = Docter::where('id', $docter_id)->first()->toArray();
  1092. $user_id = substr($v['receiverId'],7);
  1093. $user = User::where('id', $user_id)->first()->toArray();
  1094. $send_time = date('Y-m-d H:i', round($v['timestamp']/1000));
  1095. if ($v['type'] != 'text') {
  1096. $text = '图片语音类消息';
  1097. }
  1098. else {
  1099. $payload = json_decode($v['payload'], true);
  1100. $text = !empty($payload['text']) ? $payload['text'] : '文字类消息';
  1101. }
  1102. $official_arr = [$docter['openid'], $user['nickname'], $text, $send_time];
  1103. send_wechat_message_to_docter(12, $official_arr);
  1104. }
  1105. else {
  1106. // 说明是医生给用户发的, 就给用户端发消息
  1107. $reminderController->ReplyReminder(substr($v['receiverId'],7),substr($v['senderId'],7));
  1108. }
  1109. }
  1110. }
  1111. ImMessage::insert($list);
  1112. }
  1113. return json_encode(['code'=>200,'content'=>'success']);
  1114. }catch (\Exception $e){
  1115. ImMessage::create(['text'=>json_encode($e->getFile().'的第 '.$e->getLine().'行报错:'.$e->getMessage(),true)]);
  1116. }catch (\PDOException $e){
  1117. ImMessage::create(['text'=>json_encode($e->getFile().'的第 '.$e->getLine().'行报错:'.$e->getMessage(),true)]);
  1118. }
  1119. }
  1120. /**
  1121. * 删除图片
  1122. * @return \Illuminate\Http\JsonResponse
  1123. * @throws \Illuminate\Validation\ValidationException
  1124. */
  1125. public function delFile(){
  1126. $req = request()->post();
  1127. $this->validate(request(), [
  1128. 'url' => 'required|url'
  1129. ]);
  1130. $tem = parse_url($req['url']);
  1131. $allPath = public_path().$tem['path'];
  1132. unlink($allPath);
  1133. return out();
  1134. }
  1135. }