line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ // ]; } /** * 发送微信小程序消息通知 * * */ public function toSendMini($notifiable) { $order = self::$order; $user = self::$user; $status = false; $merchant = AdminMerchant::byId($user->merchant_id); if (!$merchant) { Log::error('[待支付提醒错误]:商户不存在'); } $form = Auth::query()->where('user_id',$user->id)->first(); switch ($form->type){ case Auth::TYPE_WEAPP: //微信 $app = app('wechat.mini_program'); if($merchant->alipaymini_message_json!=''){ $arr = json_decode($merchant->alipaymini_message_json); $TemplateId = isset($arr[0][1])|| !empty($arr[0][1])?$arr[0][1]: Log::error('[待支付提醒错误]:商户'.$user->merchant_id.'模板ID没有配置') ; }else{ Log::error('[待支付提醒错误]:商户'.$user->merchant_id.'模板ID没有配置'); } $page = 'pages/my_riding/my_riding?order=' . $order->no . '&index=' . $order->order_type; $data = [ 'template_id' =>$TemplateId,// 所需下发的订阅模板id 'touser' => $form->credential, // 接收者(用户)的 openid 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } } 'date1' => [ // 用车时间 'value' => $order->start_use_bike_time, ], 'thing2' => [ // 骑行时间 'value' => floor($order->use_bike_time_length / 60) . 'h' . ($order->use_bike_time_length % 60) . 'm', ], 'amount3' => [ // 待支付金额 'value' => $order->pay_money, ], 'thing4' => [ // 费用明细 'value' => '点击卡片查看明细', ], ], ]; $res = $app->subscribe_message->send($data); if ($res['errcode'] !== 0) { $status = true; } break; case Auth::TYPE_ALIPAY: //支付宝 if($merchant->alipaymini_message_json!=''){ $arr = json_decode($merchant->alipaymini_message_json); $TemplateId = isset($arr[0][1])|| !empty($arr[0][1])?$arr[0][1]:Log::error('[待支付提醒错误]:商户'.$user->merchant_id.'模板ID没有配置') ; }else{ Log::error('[待支付提醒错误]:商户'.$user->merchant_id.'模板ID没有配置'); } Factory::setOptions($this->getOptions($merchant)); $toUserId = $form->credential; $formId = ''; $userTemplateId = $TemplateId; $page = 'pages/index/index'; $data = php2js([ 'keyword1'=>[ 'value' => date('Y-m-d H:i:s') ], //下单时间 'keyword2'=>[ 'value' => '你有一个未支付订单,请及时支付。点击进入小程序' ], //订单信息 'keyword3'=>[ 'value' => $order->no], //订单编号 'keyword4'=>[ 'value' => $order->pay_money ], //订单金额 ]); try { //2. 发起API调用(以支付能力下的统一收单交易创建接口为例) $res = Factory::Marketing()->TemplateMessage()->send($toUserId,$formId,$userTemplateId,$page,$data); $responseChecker = new ResponseChecker(); //3. 处理响应或异常 if ($responseChecker->success($res)) { // echo "调用发送成功"; } else { $status = true; } } catch (Exception $e) { $status = true; } break; default: Log::info('小程序信息没有被发送原因:没有查找到登录方式'); } if ($status) { Log::warning(json_encode($res)); // $config = config('easySms'); // $easySms = $easySms = new EasySms($config); app('easy_sms')->send($user->mobile, [ 'template' => 'SMS_205437076', 'data' => [ // 'truename' => $user->truename, // 'time' => $order->start_use_bike_time ] ]); } } function getOptions($merchant) { return alipay_mini_config( new Config(),$merchant); } }