indexcontroller.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Order;
  4. use App\Models\OrderPatient;
  5. use App\User;
  6. use EasyWeChat\Factory;
  7. use Illuminate\Http\Request;
  8. class indexcontroller extends Controller
  9. {
  10. public function test()
  11. {
  12. $msgType = request('type',3); //1公众号 2医生端小程序 3 用户端小程序
  13. $orderId = request('order_id'); //订单id
  14. if(empty($orderId)){
  15. return apiReturn(601,'请输入参数');
  16. }
  17. $config = [
  18. 1=>[
  19. 'app_id' => env('OFFICE_APPID', 'wx92066f7587c34617'),
  20. 'secret' => env('OFFICE_APPSECRET', 'bd7849c5259b79c41ec158173c5fb1d6'),
  21. 'response_type' => 'array'
  22. ],
  23. 2=>[
  24. 'app_id' => env('DOCTRER_WECHAT_APPID', 'wx92066f7587c34617'),
  25. 'secret' => env('DOCTRER_WECHAT_APPSECRET', 'bd7849c5259b79c41ec158173c5fb1d6'),
  26. 'response_type' => 'array'
  27. ],
  28. 3=>[
  29. 'app_id' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
  30. 'secret' => env('WECHAT_APPSECRET', 'b703596ab6cbcad5b74eb51fec2aeb0b'),
  31. 'response_type' => 'array'
  32. ],
  33. ] ;
  34. //测试环境配置
  35. // $config = [
  36. // 'app_id' => 'wx1c2357232cd25f65',
  37. // 'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
  38. // 'app_id' => 'wx13bedfcc62e9bab0',
  39. // 'secret' => '175e5518b6426dd12d3096f24ca68fb8',
  40. // 'response_type' => 'array'
  41. // oVxTzvgYlGktIDZXwfLMLQ01Tr5s
  42. // ];
  43. $order = Order::where(['id'=>$orderId])->first();
  44. if(empty($order)) return apiReturn(602,'无效订单');
  45. if(empty($order->user_id)) return apiReturn(602,'此订单用户不存在');
  46. $user = User::where('id',$order->user_id)->first();
  47. $uid = $user->unionid;
  48. $uid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
  49. $name = OrderPatient::where(['order_id'=>$orderId])->value('name');
  50. $type_arr = [1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗',5=>'儿保',6=>'服务包',7=>'充值'];
  51. $order = Order::where(['id'=>$orderId])->first();
  52. $orderType = $type_arr[$order->product_type];
  53. if(empty($user->unionid)) $uid = $user->openid;
  54. // $uid = 'o832ywXSN6RbAfJTR7rhtUQLJIis';
  55. if($msgType ==1){
  56. $app = Factory::officialAccount($config[$msgType]);
  57. $is_office = $app->user->get($uid);
  58. $data = [
  59. 'touser' =>$uid,
  60. 'template_id' => 'IABFkUm4hoY_J44a767nADSSsGnsexUS4L-lEWJx2AA',
  61. // 'miniprogram' => [
  62. // 'appid' => env('WECHAT_APPID'),
  63. // 'pagepath' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
  64. // ],
  65. 'url'=>'https://wechat.fresherbaby.com/admin',
  66. 'data' => [
  67. 'first' => '尊敬的客户,你有一笔'.$orderType.'订单已下单成功',
  68. 'keyword1' => $order->order_sn,
  69. 'keyword2' => ($order->total_amount/100).'元',
  70. 'keyword3' => '余额支付',
  71. 'remark' => '请耐心等待医生接单,如有疑问,请联系客服。',
  72. ]
  73. ];
  74. if($is_office){
  75. $app = Factory::officialAccount($config[3]);
  76. $data = [
  77. 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
  78. 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
  79. 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
  80. 'data' => [
  81. 'phrase1' => $orderType,
  82. 'name3' => $name,
  83. 'date4' => date('Y-m-d H:i:s'),
  84. 'thing8' => '你有一笔'.$orderType.'订单已成功下单请耐心等待',
  85. 'amount10' => ($order->total_amount/100).'元',
  86. ]
  87. ];
  88. }
  89. $res = $app->template_message->send($data);
  90. } else {
  91. $app = Factory::miniProgram($config[$msgType]);
  92. $data = [
  93. 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
  94. 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
  95. 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
  96. 'data' => [
  97. 'phrase1' => $orderType,
  98. 'name3' => $name,
  99. 'date4' => date('Y-m-d H:i:s'),
  100. 'thing8' => '你有一笔'.$orderType.'订单已成功下单请耐心等待',
  101. 'amount10' => ($order->total_amount/100).'元',
  102. ]
  103. ];
  104. // $list = $app->subscribe_message->getTemplates();
  105. $res = $app->subscribe_message->send([
  106. 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
  107. 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
  108. 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
  109. 'data' => [
  110. 'phrase1' => $orderType,
  111. 'name3' => $name,
  112. 'date4' => date('Y-m-d H:i:s'),
  113. 'thing8' => '你有一笔'.$orderType.'订单已成功下单请耐心等待',
  114. 'amount10' => ($order->total_amount/100).'元',
  115. ]
  116. ]);
  117. }
  118. // oVxTzvgYlGktIDZXwfLMLQ01Tr5s 自己 oVxTzvhu4gs4RyCt4kJDRWOgsUXw周璐 oVxTzvgu4XnI5F2aF7DcrbJIp5fI 间行 oVxTzvl8DYQblYmLCIK3UXW_8jAY 落雨桐
  119. // $renyuan = ['o481Y5AtcbnOQef1vc4rL4TwYpDU', 'oVxTzvgYlGktIDZXwfLMLQ01Tr5s']; //周璐
  120. if($res['errcode'] == 0) return apiReturn(200,'发送成功');
  121. return apiReturn($res['errcode'],$res['errmsg']);
  122. }
  123. }