微信发送红包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//发送红包start
$url 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
 
//获取openID
$uid $list['uid'];
$result  = pdo_fetch("SELECT openid FROM ims_meepo_online_user WHERE id=:id",array(':id'=>$uid));
$open_id $result['openid'];
$money   = (int)$list['money'];
 
$package array();
$package['nonce_str'] = random(8);
$package['mch_billno'] = 'ydl'.rand(10000000000000,99999999999999);
$package['mch_id'] = '1515256111';
$package['wxappid'] = 'wx57a837f1e72026c3';
$package['send_name'] = 'xxxx';
$package['re_openid'] = $open_id;
$package['total_amount'] = $money*100;
$package['total_num'] = 1;
$package['wishing'] = 'xxxxxx'.date('Y-m-d');
$package['client_ip'] = CLIENT_IP;
$package['act_name'] = 'xxxxx';
$package['remark'] = 'xxxxxxxxxxxx.';
 
ksort($package, SORT_STRING);
$string1 '';
foreach($package as $key => $v) {
if (empty($v)) {
continue;
}
$string1 .= "{$key}={$v}&";
}
$string1 .= "key=2nHuHsDijB4Ye7mNN22QxFAP3AW6l3hT";
 
$package['sign'] = strtoupper(md5($string1));
$dat = array2xml($package);
 
load()->func('communication');
 
$certPath 'xxxxxx/cert/apiclient_cert.pem';
$keyPath 'xxxxxx/cert/apiclient_key.pem';
 
$extra array(
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_SSL_VERIFYHOST=>false,
CURLOPT_SSLCERTTYPE=>'PEM',
CURLOPT_SSLKEYTYPE=>'PEM',
CURLOPT_SSLCERT=>$certPath,
CURLOPT_SSLKEY=>$keyPath,
CURLOPT_POST=>1
);
$response = ihttp_request($url$dat$extra);
 
// print_r($response);
// exit;
 
// echo $response;