From 20558097083ee731f68ea3b529a1f5d05e22b750 Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 19 Oct 2020 15:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AF=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=B0=9D=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=E5=BD=93=E9=9D=A2=E4=BB=98=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/MiniprogramService.php | 77 +++++++++++++------ .../MiniprogramServiceInterface.php | 5 +- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/app/Service/v3/Implementations/MiniprogramService.php b/app/Service/v3/Implementations/MiniprogramService.php index 4996a93..bb7b66c 100644 --- a/app/Service/v3/Implementations/MiniprogramService.php +++ b/app/Service/v3/Implementations/MiniprogramService.php @@ -124,7 +124,16 @@ class MiniprogramService implements MiniprogramServiceInterface 'remark' => '感谢您的使用!' ]; - $ret_store = $this->sendTempMsg($store['openid'], 'lxVbC6PVpKbiO44bYqLmacl-BaME70D47Q0jn2Link0',$data_store); + // $ret_store = $this->sendTempMsg($store['openid'], 'lxVbC6PVpKbiO44bYqLmacl-BaME70D47Q0jn2Link0',$data_store); + $ret_store = $this->sendTempMsg( + $store['openid'], + 'b9SR_3j6GhJvVjuIoYlil4-m09plcjNnI5lls1wHfpo', + $data_store, + true, + '/pages/orderDetail/orderDetail?global_order_id='.$globalOrderId, + '1461', + $item['money'] + ); } } @@ -152,7 +161,7 @@ class MiniprogramService implements MiniprogramServiceInterface /** * @inheritDoc */ - public function sendTempMsg($openid, $template_id, $data, $redirect_url = '', $applet_config = ['appid' => '', 'pagepath' => '']) + public function sendTempMsg($openid, $template_id, $data, $isApplet = false, $redirect_url = '', $appletFormId = '', $appletEmKeyword = '', $applet_config = ['appid' => '', 'pagepath' => '']) { if (empty($openid) || empty($template_id) || empty($data)) { return ; @@ -168,6 +177,15 @@ class MiniprogramService implements MiniprogramServiceInterface ] ]; + if ($isApplet) { + $template['weapp_template_msg'] = [ + 'template_id' => $template_id, + 'page' => $redirect_url, + 'form_id' => $appletFormId, + 'emphasis_keyword' => $appletEmKeyword, + ]; + } + // 看看有没有小程序跳转的要求 $template['mp_template_msg']['miniprogram'] = $applet_config; @@ -176,32 +194,47 @@ class MiniprogramService implements MiniprogramServiceInterface return false; } - if (is_array($data['first'])) { - $template['mp_template_msg']['data']['first']['value'] = $data['first'][0] ?? ''; - $template['mp_template_msg']['data']['first']['color'] = $data['first'][1] ?? ''; - } else { - $template['mp_template_msg']['data']['first']['value'] = $data['first']; - } + if ( !$isApplet ) { + if (is_array($data['first'])) { + $template['mp_template_msg']['data']['first']['value'] = $data['first'][0] ?? ''; + $template['mp_template_msg']['data']['first']['color'] = $data['first'][1] ?? ''; + } else { + $template['mp_template_msg']['data']['first']['value'] = $data['first']; + } - if (isset($data['keyword'])&&is_array($data['keyword'])) { - foreach ($data['keyword'] as $key => &$keyword) { - $index = $key+1; + if (isset($data['keyword'])&&is_array($data['keyword'])) { + foreach ($data['keyword'] as $key => &$keyword) { + $index = $key+1; - if (is_array($keyword)) { - $template['mp_template_msg']['data']['keyword'.$index]['value'] = $keyword[0] ?? ''; - $template['mp_template_msg']['data']['keyword'.$index]['color'] = $keyword[1] ?? ''; - } else { - $template['mp_template_msg']['data']['keyword'.$index]['value'] = $keyword; - } + if (is_array($keyword)) { + $template['mp_template_msg']['data']['keyword'.$index]['value'] = $keyword[0] ?? ''; + $template['mp_template_msg']['data']['keyword'.$index]['color'] = $keyword[1] ?? ''; + } else { + $template['mp_template_msg']['data']['keyword'.$index]['value'] = $keyword; + } + } } - } - if (is_array($data['remark'])) { - $template['mp_template_msg']['data']['remark']['value'] = $data['remark'][0] ?? ''; - $template['mp_template_msg']['data']['remark']['color'] = $data['remark'][1] ?? ''; + if (is_array($data['remark'])) { + $template['mp_template_msg']['data']['remark']['value'] = $data['remark'][0] ?? ''; + $template['mp_template_msg']['data']['remark']['color'] = $data['remark'][1] ?? ''; + } else { + $template['mp_template_msg']['data']['remark']['value'] = $data['remark']; + } } else { - $template['mp_template_msg']['data']['remark']['value'] = $data['remark']; + if (isset($data['keyword'])&&is_array($data['keyword'])) { + foreach ($data['keyword'] as $key => &$keyword) { + $index = $key+1; + + if (is_array($keyword)) { + $template['weapp_template_msg']['data']['keyword'.$index]['value'] = $keyword[0] ?? ''; + } else { + $template['weapp_template_msg']['data']['keyword'.$index]['value'] = $keyword; + } + + } + } } $app = Factory::miniProgram(config('wechat.applet')); diff --git a/app/Service/v3/Interfaces/MiniprogramServiceInterface.php b/app/Service/v3/Interfaces/MiniprogramServiceInterface.php index 9112b83..1521115 100644 --- a/app/Service/v3/Interfaces/MiniprogramServiceInterface.php +++ b/app/Service/v3/Interfaces/MiniprogramServiceInterface.php @@ -33,9 +33,12 @@ interface MiniprogramServiceInterface * @param $openid * @param $template_id * @param $data + * @param bool $isApplet * @param string $redirect_url + * @param string $appletFormId + * @param string $appletEmKeyword * @param string[] $applet_config * @return mixed */ - public function sendTempMsg($openid, $template_id, $data, $redirect_url = '', $applet_config = ['appid' => '', 'pagepath' => '']); + public function sendTempMsg($openid, $template_id, $data, $isApplet = false, $redirect_url = '', $appletFormId = '', $appletEmKeyword = '', $applet_config = ['appid' => '', 'pagepath' => '']); } \ No newline at end of file