Passed
Push — master ( f17217...1fc1f2 )
by Dong
08:32
created

QuickSend   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 58
c 1
b 0
f 0
dl 0
loc 137
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A miniProgram() 0 27 2
A offical() 0 21 3
A alisms() 0 14 2
A mail() 0 25 5
1
<?php
2
3
namespace Dongdavid\Notify;
4
5
class QuickSend
6
{
7
    /**
8
     * 微信公众号模版消息
9
     * @param $access_token
10
     * @param $openid
11
     * @param $template_id
12
     * @param $data
13
     * @param  string  $url
14
     * @param  false  $miniProgram
15
     * @return bool|string
16
     */
17
    public static function offical($access_token, $openid, $template_id, $data, $url = '', $miniProgram = false)
18
    {
19
        $msg = [
20
            'type' => 'wechatoffical',
21
            'config' => [
22
                'access_token' => $access_token,
23
            ],
24
            'data' => array(
25
                "touser" => $openid,
26
                "template_id" => $template_id,
27
                "data" => $data,
28
                'url' => $url,
29
            )
30
        ];
31
        if ($miniProgram) {
0 ignored issues
show
introduced by
The condition $miniProgram is always false.
Loading history...
32
            $msg['data']['miniprogram'] = $miniProgram;
33
        }
34
        try {
35
            return Notify::send($msg);
36
        } catch (\Exception $e) {
37
            return $e->getMessage();
38
        }
39
    }
40
41
    /**
42
     * 微信小程序
43
     * @param $access_token
44
     * @param $openid
45
     * @param $template_id
46
     * @param $data
47
     * @param  string  $page
48
     * @param  string  $miniprogram_state
49
     * @param  string  $lang
50
     * @return bool|string
51
     */
52
    public static function miniProgram(
53
        $access_token,
54
        $openid,
55
        $template_id,
56
        $data,
57
        $page = '',
58
        $miniprogram_state = 'formal',
59
        $lang = 'zh_CN'
60
    ) {
61
        $msg = [
62
            'type' => 'miniprogram',
63
            'config' => [
64
                'access_token' => $access_token,
65
            ],
66
            'data' => array(
67
                "touser" => $openid,
68
                "template_id" => $template_id,
69
                "data" => $data,
70
                'page' => $page,
71
                'miniprogram_state' => $miniprogram_state,
72
                'lang' => $lang,
73
            )
74
        ];
75
        try {
76
            return Notify::send($msg);
77
        } catch (\Exception $e) {
78
            return $e->getMessage();
79
        }
80
    }
81
82
    /**
83
     * 发送邮件
84
     * @param $config
85
     * @param $subject
86
     * @param $body
87
     * @param $to
88
     * @param  array  $attachments
89
     * @param  array  $cc
90
     * @param  array  $bcc
91
     * @return bool|string
92
     */
93
    public static function mail($config,$subject,$body,$to,$attachments = [],$cc = [],$bcc=[])
94
    {
95
        $msg = [
96
            'type'=>'email',
97
            'config'=>$config,
98
            'data'=>[
99
                'subject'=>$subject,
100
                'body'=>$body,
101
                'to'=>$to,
102
            ],
103
        ];
104
        if (!empty($attachments)){
105
            $msg['data']['attachments'] = $attachments;
106
        }
107
        if (!empty($cc)){
108
            $msg['data']['cc'] = $cc;
109
        }
110
        if (!empty($bcc)){
111
            $msg['data']['bcc'] = $bcc;
112
        }
113
114
        try {
115
            return Notify::send($msg);
116
        } catch (\Exception $e) {
117
            return $e->getMessage();
118
        }
119
    }
120
121
    /**
122
     * @param $config
123
     * @param $phone
124
     * @param $template_code
125
     * @param  array  $template_param
126
     * @return array|string
127
     */
128
    public function alisms($config,$phone,$template_param = [])
129
    {
130
        $msg = [
131
            'type'=>'alisms',
132
            'config'=>$config,
133
            'data'=>[
134
                'phone'=>$phone,
135
                'template_param' => $template_param,
136
            ],
137
        ];
138
        try {
139
            return Notify::send($msg);
140
        } catch (\Exception $e) {
141
            return $e->getMessage();
142
        }
143
    }
144
}