微信发送红包

//发送红包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;