|
@@ -0,0 +1,134 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Http\Controllers;
|
|
|
|
+use App\Models\Order;
|
|
|
|
+use App\Models\OrderPatient;
|
|
|
|
+use App\User;
|
|
|
|
+use EasyWeChat\Factory;
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
+
|
|
|
|
+class indexcontroller extends Controller
|
|
|
|
+{
|
|
|
|
+ public function test()
|
|
|
|
+ {
|
|
|
|
+ $msgType = request('type',3); //1公众号 2医生端小程序 3 用户端小程序
|
|
|
|
+ $orderId = request('order_id'); //订单id
|
|
|
|
+ if(empty($orderId)){
|
|
|
|
+ return apiReturn(601,'请输入参数');
|
|
|
|
+ }
|
|
|
|
+ $config = [
|
|
|
|
+ 1=>[
|
|
|
|
+ 'app_id' => env('OFFICE_APPID', 'wx92066f7587c34617'),
|
|
|
|
+ 'secret' => env('OFFICE_APPSECRET', 'bd7849c5259b79c41ec158173c5fb1d6'),
|
|
|
|
+ 'response_type' => 'array'
|
|
|
|
+ ],
|
|
|
|
+ 2=>[
|
|
|
|
+ 'app_id' => env('DOCTRER_WECHAT_APPID', 'wx92066f7587c34617'),
|
|
|
|
+ 'secret' => env('DOCTRER_WECHAT_APPSECRET', 'bd7849c5259b79c41ec158173c5fb1d6'),
|
|
|
|
+ 'response_type' => 'array'
|
|
|
|
+ ],
|
|
|
|
+ 3=>[
|
|
|
|
+ 'app_id' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
|
|
|
|
+ 'secret' => env('WECHAT_APPSECRET', 'b703596ab6cbcad5b74eb51fec2aeb0b'),
|
|
|
|
+ 'response_type' => 'array'
|
|
|
|
+ ],
|
|
|
|
+ ] ;
|
|
|
|
+
|
|
|
|
+ //测试环境配置
|
|
|
|
+// $config = [
|
|
|
|
+// 'app_id' => 'wx1c2357232cd25f65',
|
|
|
|
+// 'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
|
|
|
|
+// 'app_id' => 'wx13bedfcc62e9bab0',
|
|
|
|
+// 'secret' => '175e5518b6426dd12d3096f24ca68fb8',
|
|
|
|
+// 'response_type' => 'array'
|
|
|
|
+// oVxTzvgYlGktIDZXwfLMLQ01Tr5s
|
|
|
|
+// ];
|
|
|
|
+ $order = Order::where(['id'=>$orderId])->first();
|
|
|
|
+ if(empty($order)) return apiReturn(602,'无效订单');
|
|
|
|
+ if(empty($order->user_id)) return apiReturn(602,'此订单用户不存在');
|
|
|
|
+ $user = User::where('id',$order->user_id)->first();
|
|
|
|
+ $uid = $user->unionid;
|
|
|
|
+ $uid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
|
|
|
|
+ $name = OrderPatient::where(['order_id'=>$orderId])->value('name');
|
|
|
|
+ $type_arr = [1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗',5=>'儿保',6=>'服务包',7=>'充值'];
|
|
|
|
+ $order = Order::where(['id'=>$orderId])->first();
|
|
|
|
+ $orderType = $type_arr[$order->product_type];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(empty($user->unionid)) $uid = $user->openid;
|
|
|
|
+// $uid = 'o832ywXSN6RbAfJTR7rhtUQLJIis';
|
|
|
|
+
|
|
|
|
+ if($msgType ==1){
|
|
|
|
+ $app = Factory::officialAccount($config[$msgType]);
|
|
|
|
+ $is_office = $app->user->get($uid);
|
|
|
|
+ $data = [
|
|
|
|
+ 'touser' =>$uid,
|
|
|
|
+ 'template_id' => 'IABFkUm4hoY_J44a767nADSSsGnsexUS4L-lEWJx2AA',
|
|
|
|
+// 'miniprogram' => [
|
|
|
|
+// 'appid' => env('WECHAT_APPID'),
|
|
|
|
+// 'pagepath' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
|
|
|
|
+// ],
|
|
|
|
+ 'url'=>'https://wechat.fresherbaby.com/admin',
|
|
|
|
+ 'data' => [
|
|
|
|
+ 'first' => '尊敬的客户,你有一笔'.$orderType.'订单已下单成功',
|
|
|
|
+ 'keyword1' => $order->order_sn,
|
|
|
|
+ 'keyword2' => ($order->total_amount/100).'元',
|
|
|
|
+ 'keyword3' => '余额支付',
|
|
|
|
+ 'remark' => '请耐心等待医生接单,如有疑问,请联系客服。',
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ if($is_office){
|
|
|
|
+ $app = Factory::officialAccount($config[3]);
|
|
|
|
+ $data = [
|
|
|
|
+ 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
|
|
|
|
+ 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
|
|
|
|
+ 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
|
|
|
|
+ 'data' => [
|
|
|
|
+ 'phrase1' => $orderType,
|
|
|
|
+ 'name3' => $name,
|
|
|
|
+ 'date4' => date('Y-m-d H:i:s'),
|
|
|
|
+ 'thing8' => '你有一笔'.$orderType.'订单已成功下单请耐心等待',
|
|
|
|
+ 'amount10' => ($order->total_amount/100).'元',
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $res = $app->template_message->send($data);
|
|
|
|
+ } else {
|
|
|
|
+ $app = Factory::miniProgram($config[$msgType]);
|
|
|
|
+
|
|
|
|
+ $data = [
|
|
|
|
+ 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
|
|
|
|
+ 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
|
|
|
|
+ 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
|
|
|
|
+ 'data' => [
|
|
|
|
+ 'phrase1' => $orderType,
|
|
|
|
+ 'name3' => $name,
|
|
|
|
+ 'date4' => date('Y-m-d H:i:s'),
|
|
|
|
+ 'thing8' => '你有一笔'.$orderType.'订单已成功下单请耐心等待',
|
|
|
|
+ 'amount10' => ($order->total_amount/100).'元',
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+// $list = $app->subscribe_message->getTemplates();
|
|
|
|
+ $res = $app->subscribe_message->send([
|
|
|
|
+ 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
|
|
|
|
+ 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
|
|
|
|
+ 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
|
|
|
|
+ 'data' => [
|
|
|
|
+ 'phrase1' => $orderType,
|
|
|
|
+ 'name3' => $name,
|
|
|
|
+ 'date4' => date('Y-m-d H:i:s'),
|
|
|
|
+ 'thing8' => '你有一笔'.$orderType.'订单已成功下单请耐心等待',
|
|
|
|
+ 'amount10' => ($order->total_amount/100).'元',
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// oVxTzvgYlGktIDZXwfLMLQ01Tr5s 自己 oVxTzvhu4gs4RyCt4kJDRWOgsUXw周璐 oVxTzvgu4XnI5F2aF7DcrbJIp5fI 间行 oVxTzvl8DYQblYmLCIK3UXW_8jAY 落雨桐
|
|
|
|
+// $renyuan = ['o481Y5AtcbnOQef1vc4rL4TwYpDU', 'oVxTzvgYlGktIDZXwfLMLQ01Tr5s']; //周璐
|
|
|
|
+
|
|
|
|
+ if($res['errcode'] == 0) return apiReturn(200,'发送成功');
|
|
|
|
+ return apiReturn($res['errcode'],$res['errmsg']);
|
|
|
|
+ }
|
|
|
|
+}
|