| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace addons\Course\common\logic;
- use addons\Course\common\models\AddonsCourseChapter;
- use common\helpers\wechat\WechatTemplate;
- use common\models\mall\Mall;
- use common\models\user\User;
- class Video
- {
- public static function sendWechatMessage($params)
- {
- $user_id = $params['user_id'];
- $mall_id = $params['mall_id'];
- $mall = Mall::findOne(['id'=>$mall_id]);
- if(empty($mall)) return false ;
- $user = User::findOne(['id' => $user_id]);
- if (empty($user['parent_id'])) return false;
- $parent_id = $user['parent_id'];
- $wechat = new WechatTemplate($mall_id);
- if(!$wechat->is_open()) return false;
- $platform = $wechat->getPlatForm();
- $wechat->is_platform_wechat($parent_id);
- $send_data = [
- // 'first' => '您好,您的订单已生成',
- // 'keyword1' => date("Y-m-d H:i:s", $param['created_at']),
- // 'keyword2' => $param['goods_name'],
- // 'keyword3' => $param['order_no'],
- // 'keyword4' => $param['receiver_name'],
- // 'keyword5' => $param['address'],
- // 'remark' => '感谢您的使用'
- ];
- $configs = \Yii::$app->services->setting->addons->get($mall_id, 'Course', 'basic');
- if (empty($configs['template_id'])) return false;
- $template_id = $configs['template_id'];
- $page_path = 'plugins/pages/order/detail';
- $page_path =$page_path."?id=" .'1'.'&sign='.$mall['mall_sign'];
- $h5_url = self::getH5($mall_id).$page_path;
- switch ($platform) {
- case WechatTemplate::PLATFORM_WECHAT:
- $result = $wechat->sendWechat($wechat->openid, $template_id, $h5_url, $send_data);
- break;
- case WechatTemplate::PLATFORM_MP_MX:
- $result = $wechat->sendMiniApp($wechat->openid, $template_id, $h5_url, $send_data, $page_path);
- break;
- }
- }
- private static function getH5($mall_id){
- $h5 = \Yii::$app->services->setting->mall->get($mall_id, 'basic.web_url');
- if (empty($h5)) throw new \Exception('h5域名没有配置');
- return substr($h5, 0, strpos($h5, '?'));
- }
- }
|