|
@@ -6,67 +6,139 @@ use think\Log;
|
|
|
|
|
|
class WechatService {
|
|
|
|
|
|
+ private const PUSH_TYPE = [
|
|
|
+ 'REMOTE_DIAGNOSIS_PATIENT_PAY' => 1,
|
|
|
+ 'REMOTE_DIAGNOSIS_FINISH' => 2,
|
|
|
+ 'REMOTE_DIAGNOSIS_CANCEL' => 3,
|
|
|
+ 'REMOTE_DIAGNOSIS_REFUND' => 4
|
|
|
+ ];
|
|
|
|
|
|
- public function pushWechatOrder($exam_id) {
|
|
|
- $openids = $this->getPushOpenId($exam_id);
|
|
|
+ private const BASE_URL = "http://wechat.pacsonline.cn/wx_patient/api/";
|
|
|
+ public function pushWechatOrder($order_id) {
|
|
|
+ $order = $this->getPushOrder($order_id);
|
|
|
+ $orderStr = $this->getPushContent($order);
|
|
|
+ $openids = $this->getPushOpenId($order_id['exam_id']);
|
|
|
if(!$openids) {
|
|
|
log::record('---------没有找到对应openid--------');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
foreach($openids as $v) {
|
|
|
- $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
|
|
|
- $full_url = $url . $v['openid'];
|
|
|
+ $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_REFUND'], $v['openid'], $v['source'], $orderStr);
|
|
|
+ // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
|
|
|
+ // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
|
|
|
// 请求
|
|
|
- log::record('---------发送微信通知-发起订单-------');
|
|
|
- log::record($full_url);
|
|
|
- $res = $this->curl_request($full_url, 'GET');
|
|
|
+ log::record('---------发送微信通知-完成订单-------');
|
|
|
+ log::record($url);
|
|
|
+ $res = $this->curl_request($url, 'GET');
|
|
|
log::record('---------微信通知结果--------');
|
|
|
log::record($res);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public function pushWechatCancel($exam_id) {
|
|
|
- $openids = $this->getPushOpenId($exam_id);
|
|
|
+ public function pushWechatCancel($order_id) {
|
|
|
+ $order = $this->getPushOrder($order_id);
|
|
|
+ $orderStr = $this->getPushContent($order);
|
|
|
+ $openids = $this->getPushOpenId($order_id['exam_id']);
|
|
|
if(!$openids) {
|
|
|
log::record('---------没有找到对应openid--------');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
foreach($openids as $v) {
|
|
|
- $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
|
|
|
- $full_url = $url . $v['openid'];
|
|
|
+ $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_REFUND'], $v['openid'], $v['source'], $orderStr);
|
|
|
+ // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
|
|
|
+ // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
|
|
|
// 请求
|
|
|
- log::record('---------发送微信通知-取消订单-------');
|
|
|
- log::record($full_url);
|
|
|
- $res = $this->curl_request($full_url, 'GET');
|
|
|
+ log::record('---------发送微信通知-完成订单-------');
|
|
|
+ log::record($url);
|
|
|
+ $res = $this->curl_request($url, 'GET');
|
|
|
log::record('---------微信通知结果--------');
|
|
|
log::record($res);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public function pushWechatComplete($exam_id) {
|
|
|
- $openids = $this->getPushOpenId($exam_id);
|
|
|
+ public function pushWechatComplete($order_id) {
|
|
|
+ $order = $this->getPushOrder($order_id);
|
|
|
+ $orderStr = $this->getPushContent($order);
|
|
|
+ $openids = $this->getPushOpenId($order_id['exam_id']);
|
|
|
if(!$openids) {
|
|
|
log::record('---------没有找到对应openid--------');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
foreach($openids as $v) {
|
|
|
- $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
|
|
|
- $full_url = $url . $v['openid'];
|
|
|
+ $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_REFUND'], $v['openid'], $v['source'], $orderStr);
|
|
|
+ // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
|
|
|
+ // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
|
|
|
// 请求
|
|
|
log::record('---------发送微信通知-完成订单-------');
|
|
|
- log::record($full_url);
|
|
|
- $res = $this->curl_request($full_url, 'GET');
|
|
|
+ log::record($url);
|
|
|
+ $res = $this->curl_request($url, 'GET');
|
|
|
log::record('---------微信通知结果--------');
|
|
|
log::record($res);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public function pushWechatRefund($order_id) {
|
|
|
+ $order = $this->getPushOrder($order_id);
|
|
|
+ $orderStr = $this->getPushContent($order);
|
|
|
+ $openids = $this->getPushOpenId($order_id['exam_id']);
|
|
|
+ if(!$openids) {
|
|
|
+ log::record('---------没有找到对应openid--------');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($openids as $v) {
|
|
|
+ $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_REFUND'], $v['openid'], $v['source'], $orderStr);
|
|
|
+ // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
|
|
|
+ // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
|
|
|
+ // 请求
|
|
|
+ log::record('---------发送微信通知-完成订单-------');
|
|
|
+ log::record($url);
|
|
|
+ $res = $this->curl_request($url, 'GET');
|
|
|
+ log::record('---------微信通知结果--------');
|
|
|
+ log::record($res);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getPushContent($order) {
|
|
|
+ $content = [
|
|
|
+ 'out_trade_no' => $order['order_id'],
|
|
|
+ 'name' => urlencode($order['name']),
|
|
|
+ 'total_fee' => $order['order_money']
|
|
|
+ ];
|
|
|
+ return json_encode($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
|
|
|
+ // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
|
|
|
+
|
|
|
+ private function getFullUrl($pushType, $openid, $source, $content) {
|
|
|
+ return self::BASE_URL."sendMsg?pushType=".$pushType."&openid=".$openid."&source=".source."&content=".$content;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getPushOrder($order_id) {
|
|
|
+ $order = DB::table('remote_order')->where('id', $order_id)->field('application_id, order_money')->find();
|
|
|
+ if($order) {
|
|
|
+ $application = DB::table('remote_application')->where('id', $order['application_id'])->field('exam_id')->find();
|
|
|
+ $exam = DB::table('exams')->where('id', $application['exam_id'])->field('patient_id')->find();
|
|
|
+ $patient = DB::table('patient_infos')->where('id', $exam['patient_id'])->field('name')->find();
|
|
|
+ if($application) {
|
|
|
+ return [
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'order_money' => $order['order_money'],
|
|
|
+ 'exam_id' => $application['exam_id'],
|
|
|
+ 'name' => $patient['name']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private function getPushOpenId($exam_id) {
|
|
|
$exams = DB::table("exams")
|
|
|
->alias('e')
|
|
@@ -110,7 +182,7 @@ class WechatService {
|
|
|
$options[] = $phone;
|
|
|
}
|
|
|
|
|
|
- $sql = "select wx_openid as openid from user where id in (".$sql1." union ".$sql2.")";
|
|
|
+ $sql = "select wx_openid as openid, source from user where id in (".$sql1." union ".$sql2.")";
|
|
|
log::record('---------微信推送sql--------');
|
|
|
log::record($sql);
|
|
|
return Db::query($sql, $options);
|