Issues (108)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Payment/LuckyMoney/API.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace EntWeChat\Payment\LuckyMoney;
4
5
use EntWeChat\Core\AbstractAPI;
6
use EntWeChat\Payment\Merchant;
7
use EntWeChat\Support\Collection;
8
use EntWeChat\Support\XML;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * Class API.
13
 */
14
class API extends AbstractAPI
15
{
16
    /**
17
     * Merchant instance.
18
     *
19
     * @var Merchant
20
     */
21
    protected $merchant;
22
23
    // api
24
    const API_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
25
    const API_SEND_GROUP = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack';
26
    const API_QUERY = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo';
27
    const API_PREPARE = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder';
28
29
    // LuckyMoney type
30
    const TYPE_NORMAL = 'NORMAL';
31
    const TYPE_GROUP = 'GROUP';
32
33
    // Risk control type.
34
    const RISK_NORMAL = 'NORMAL';
35
    const RISK_IGN_FREQ_LMT = 'IGN_FREQ_LMT';
36
    const RISK_IGN_DAY_LMT = 'IGN_DAY_LMT';
37
    const RISK_IGN_FREQ_DAY_LMT = 'IGN_FREQ_DAY_LMT';
38
39
    /**
40
     * API constructor.
41
     *
42
     * @param \EntWeChat\Payment\Merchant $merchant
43
     */
44
    public function __construct(Merchant $merchant)
45
    {
46
        $this->merchant = $merchant;
47
    }
48
49
    /**
50
     * Prepare luckymoney.
51
     *
52
     * @param array $params
53
     *
54
     * @return \EntWeChat\Support\Collection
55
     */
56
    public function prepare(array $params)
57
    {
58
        $params['wxappid'] = $this->merchant->app_id;
59
60
        // XXX: PLEASE DON'T CHANGE THE FOLLOWING LINES.
61
        $params['auth_mchid'] = '1000052601';
62
        $params['auth_appid'] = 'wxbf42bd79c4391863';
63
64
        $params['amt_type'] = 'ALL_RAND';
65
66
        return $this->request(self::API_PREPARE, $params);
67
    }
68
69
    /**
70
     * Query luckymoney.
71
     *
72
     * @param string $mchBillNo
73
     *
74
     * @return \EntWeChat\Support\Collection
75
     */
76
    public function query($mchBillNo)
77
    {
78
        $params = [
79
            'appid'      => $this->merchant->app_id,
80
            'mch_billno' => $mchBillNo,
81
            'bill_type'  => 'MCHT',
82
        ];
83
84
        return $this->request(self::API_QUERY, $params);
85
    }
86
87
    /**
88
     * Send LuckyMoney.
89
     *
90
     * @param array  $params
91
     * @param string $type
92
     *
93
     * @return \EntWeChat\Support\Collection
94
     */
95
    public function send(array $params, $type = self::TYPE_NORMAL)
96
    {
97
        $api = ($type === self::TYPE_NORMAL) ? self::API_SEND : self::API_SEND_GROUP;
98
99
        $params['wxappid'] = $this->merchant->app_id;
100
        //如果类型为分裂红则去掉client_ip参数,否则签名会出错
101
        if ($type === self::TYPE_GROUP) {
102
            unset($params['client_ip']);
103
        }
104
105
        return $this->request($api, $params);
106
    }
107
108
    /**
109
     * Send normal LuckyMoney.
110
     *
111
     * @param array $params
112
     *
113
     * @return \EntWeChat\Support\Collection
114
     */
115
    public function sendNormal($params)
116
    {
117
        $params['total_num'] = 1;
118
        $params['client_ip'] = !empty($params['client_ip']) ? $params['client_ip'] : getenv('SERVER_ADDR');
119
120
        return $this->send($params, self::TYPE_NORMAL);
121
    }
122
123
    /**
124
     * Send group luckymoney.
125
     *
126
     * @param array $params
127
     *
128
     * @return \EntWeChat\Support\Collection
129
     */
130
    public function sendGroup($params)
131
    {
132
        $params['amt_type'] = 'ALL_RAND';
133
134
        return $this->send($params, self::TYPE_GROUP);
135
    }
136
137
    /**
138
     * Merchant setter.
139
     *
140
     * @param Merchant $merchant
141
     *
142
     * @return $this
143
     */
144
    public function setMerchant(Merchant $merchant)
145
    {
146
        $this->merchant = $merchant;
147
    }
148
149
    /**
150
     * Merchant getter.
151
     *
152
     * @return Merchant
153
     */
154
    public function getMerchant()
155
    {
156
        return $this->merchant;
157
    }
158
159
    /**
160
     * Make a API request.
161
     *
162
     * @param string $api
163
     * @param array  $params
164
     * @param string $method
165
     *
166
     * @return \EntWeChat\Support\Collection
167
     */
168 View Code Duplication
    protected function request($api, array $params, $method = 'post')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
    {
170
        $params = array_filter($params);
171
        $params['mch_id'] = $this->merchant->merchant_id;
172
        $params['nonce_str'] = uniqid();
173
        $params['sign'] = \EntWeChat\Payment\generate_sign($params, $this->merchant->key, 'md5');
174
175
        $options = [
176
            'body'    => XML::build($params),
177
            'cert'    => $this->merchant->get('cert_path'),
178
            'ssl_key' => $this->merchant->get('key_path'),
179
        ];
180
181
        return $this->parseResponse($this->getHttp()->request($api, $method, $options));
182
    }
183
184
    /**
185
     * Parse Response XML to array.
186
     *
187
     * @param \Psr\Http\Message\ResponseInterface|string $response
188
     *
189
     * @return \EntWeChat\Support\Collection
190
     */
191
    protected function parseResponse($response)
192
    {
193
        if ($response instanceof ResponseInterface) {
194
            $response = $response->getBody();
195
        }
196
197
        return new Collection((array) XML::parse($response));
198
    }
199
}
200