WechatService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\inter\service;
  3. use think\Db;
  4. class WechatService {
  5. public static function pushWechatOrder($exam_id) {
  6. var_dump($exam_id);
  7. $openids = self::getPushOpenId($exam_id);
  8. var_dump($openids);
  9. if(!$openids) {
  10. log::record('---------没有找到对应openid--------');
  11. return false;
  12. }
  13. foreach($openids as $v) {
  14. $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
  15. $full_url = $url . $v['openid'];
  16. // 请求
  17. $res = self::curl_request($full_url, 'GET');
  18. }
  19. return true;
  20. // http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=
  21. }
  22. public static function pushWechatCancel() {
  23. }
  24. public static function pushWechatComplete() {
  25. }
  26. private static function getPushOpenId($exam_id) {
  27. $exams = DB::table("exams")
  28. ->alias('e')
  29. ->join('studies s', 'e.study_id = s.id')
  30. ->join('patient_infos pi', 'e.patient_id = pi.id')
  31. ->field('e.patient_id, s.accession_num, s.studyid, pi.temp_patient_id, pi.card_num, pi.phone')
  32. ->where('e.id', $exam_id)
  33. ->find();
  34. if(!$exams) {
  35. return false;
  36. }
  37. $options = [];
  38. $accession_num = $exams['accession_num'];
  39. $studyid = $exams['studyid'];
  40. $patient_id = $exams['patient_id'];
  41. $temp_patient_id = $exams['temp_patient_id'];
  42. $card_num = $exams['card_num'];
  43. $phone = $exams['phone'];
  44. $sql1 = "select user_id as uid from user_bind where patient_id = ?";
  45. $options[] = $patient_id;
  46. $sql2 = "select uid from wechat_bind where ";
  47. $sql2 .= "(patientCode = ?";
  48. $options[] = $temp_patient_id;
  49. if(!empty($accession_num)) {
  50. $sql2 .= " or patientCode = ?";
  51. $options[] = $accession_num;
  52. }
  53. if(!empty($studyid)) {
  54. $sql2 .= " or patientCode = ?";
  55. $options[] = $studyid;
  56. }
  57. $sql2 .=")";
  58. if($card_num) {
  59. $sql2 .= " or idcard = ?";
  60. $options[] = $card_num;
  61. }
  62. if($card_num) {
  63. $sql2 .= " or phone = ?";
  64. $options[] = $phone;
  65. }
  66. $sql = "select wx_openid as openid from user where id in (".$sql1." union ".$sql2.")";
  67. log::record('---------微信推送sql--------');
  68. log::record($sql);
  69. return Db::query($sql, $options);
  70. }
  71. private static function curl_request($url,$method='get',$data=null,$https=true){
  72. //1.初识化curl
  73. $ch = curl_init($url);
  74. //2.根据实际请求需求进行参数封装
  75. //返回数据不直接输出
  76. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  77. //如果是https请求
  78. if($https === true){
  79. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  80. curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
  81. }
  82. //如果是post请求
  83. if($method === 'post'){
  84. //开启发送post请求选项
  85. curl_setopt($ch,CURLOPT_POST,true);
  86. //发送post的数据
  87. curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
  88. }
  89. //3.发送请求
  90. $result = curl_exec($ch);
  91. //4.返回返回值,关闭连接
  92. curl_close($ch);
  93. return $result;
  94. }
  95. }