Video.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace addons\Course\common\logic;
  3. use addons\Course\common\models\AddonsCourseChapter;
  4. use common\helpers\wechat\WechatTemplate;
  5. use common\models\mall\Mall;
  6. use common\models\user\User;
  7. class Video
  8. {
  9. public static function sendWechatMessage($params)
  10. {
  11. $user_id = $params['user_id'];
  12. $mall_id = $params['mall_id'];
  13. $mall = Mall::findOne(['id'=>$mall_id]);
  14. if(empty($mall)) return false ;
  15. $user = User::findOne(['id' => $user_id]);
  16. if (empty($user['parent_id'])) return false;
  17. $parent_id = $user['parent_id'];
  18. $wechat = new WechatTemplate($mall_id);
  19. if(!$wechat->is_open()) return false;
  20. $platform = $wechat->getPlatForm();
  21. $wechat->is_platform_wechat($parent_id);
  22. $send_data = [
  23. // 'first' => '您好,您的订单已生成',
  24. // 'keyword1' => date("Y-m-d H:i:s", $param['created_at']),
  25. // 'keyword2' => $param['goods_name'],
  26. // 'keyword3' => $param['order_no'],
  27. // 'keyword4' => $param['receiver_name'],
  28. // 'keyword5' => $param['address'],
  29. // 'remark' => '感谢您的使用'
  30. ];
  31. $configs = \Yii::$app->services->setting->addons->get($mall_id, 'Course', 'basic');
  32. if (empty($configs['template_id'])) return false;
  33. $template_id = $configs['template_id'];
  34. $page_path = 'plugins/pages/order/detail';
  35. $page_path =$page_path."?id=" .'1'.'&sign='.$mall['mall_sign'];
  36. $h5_url = self::getH5($mall_id).$page_path;
  37. switch ($platform) {
  38. case WechatTemplate::PLATFORM_WECHAT:
  39. $result = $wechat->sendWechat($wechat->openid, $template_id, $h5_url, $send_data);
  40. break;
  41. case WechatTemplate::PLATFORM_MP_MX:
  42. $result = $wechat->sendMiniApp($wechat->openid, $template_id, $h5_url, $send_data, $page_path);
  43. break;
  44. }
  45. }
  46. private static function getH5($mall_id){
  47. $h5 = \Yii::$app->services->setting->mall->get($mall_id, 'basic.web_url');
  48. if (empty($h5)) throw new \Exception('h5域名没有配置');
  49. return substr($h5, 0, strpos($h5, '?'));
  50. }
  51. }