WechatService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\inter\service;
  3. use think\Db;
  4. class WechatService {
  5. public function pushWechatOrder($exam_id) {
  6. $openids = $this->getPushOpenId($exam_id);
  7. var_dump($openids);
  8. if(!$openids) {
  9. log::record('---------没有找到对应openid--------');
  10. return false;
  11. }
  12. foreach($openids as $v) {
  13. $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
  14. $full_url = $url . $v['openid'];
  15. // 请求
  16. $res = $this->curl_request($full_url, 'GET');
  17. }
  18. return true;
  19. // http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=
  20. }
  21. public function pushWechatCancel() {
  22. }
  23. public function pushWechatComplete() {
  24. }
  25. private function getPushOpenId($exam_id) {
  26. $exams = DB::table("exams")
  27. ->alias('e')
  28. ->join('studies s', 'e.study_id = s.id')
  29. ->join('patient_infos pi', 'e.patient_id = pi.id')
  30. ->field('e.patient_id, s.accession_num, s.studyid, pi.temp_patient_id, pi.card_num, pi.phone')
  31. ->where('e.id', $exam_id)
  32. ->find();
  33. if(!$exams) {
  34. return false;
  35. }
  36. $options = [];
  37. $accession_num = $exams['accession_num'];
  38. $studyid = $exams['studyid'];
  39. $patient_id = $exams['patient_id'];
  40. $temp_patient_id = $exams['temp_patient_id'];
  41. $card_num = $exams['card_num'];
  42. $phone = $exams['phone'];
  43. $sql1 = "select user_id as uid from user_bind where patient_id = ?";
  44. $options[] = $patient_id;
  45. $sql2 = "select uid from wechat_bind where ";
  46. $sql2 .= "(patientCode = ?";
  47. $options[] = $temp_patient_id;
  48. if(!empty($accession_num)) {
  49. $sql2 .= " or patientCode = ?";
  50. $options[] = $accession_num;
  51. }
  52. if(!empty($studyid)) {
  53. $sql2 .= " or patientCode = ?";
  54. $options[] = $studyid;
  55. }
  56. $sql2 .=")";
  57. if($card_num) {
  58. $sql2 .= " or idcard = ?";
  59. $options[] = $card_num;
  60. }
  61. if($card_num) {
  62. $sql2 .= " or phone = ?";
  63. $options[] = $phone;
  64. }
  65. $sql = "select wx_openid as openid from user where id in (".$sql1." union ".$sql2.")";
  66. log::record('---------微信推送sql--------');
  67. log::record($sql);
  68. return Db::query($sql, $options);
  69. }
  70. }