# 微信支付 - 現金紅包
現金紅包需要配置 mchid、mchkey 和 商戶證書:
```php
use Thenbsp\Wechat\Wechat;
$options = array(
'appid' => 'app id',
'appsecret' => 'app secret',
'mchid' => 'mch id',
'mchkey' => 'mch key',
'authenticate_cert' => array(
'cert' => '/path/to/apiclient_cert.pem',
'key' => '/path/to/apiclient_key.pem'
)
);
$wechat = new Wechat($options);
```
向指定用戶發發送現金紅包:
```php
use Thenbsp\Wechat\Payment\Coupon\Cash;
$options = array(
'send_name' => '公眾號名稱',
'act_name' => '活動名稱',
'remark' => '備注',
're_openid' => '接收紅包用戶 Openid',
'total_amount' => 100, // 單位為分
'total_num' => 1,
'wishing' => '祝福語',
'mch_billno' => date('YmdHis').mt_rand(10000, 99999)
);
try {
$cash = new Cash($wechat, $options);
$response = $cash->getResponse();
} catch (\InvalidArgumentException $e) {
exit($e->getMessage());
} catch (\Exception $e) {
exit($e->getMessage());
}
echo '<pre>';
print_r($response);
echo '</pre>';
```
如果發送成功,將返回以下信息:
```php
Array
(
[return_code] => SUCCESS
[return_msg] => 發放成功
[result_code] => SUCCESS
[mch_billno] => 2015122915291444042
[mch_id] => 1283267801
[wxappid] => wxd8da84ed2a26aa06
[re_openid] => ob4npwpYsDT6CQGHRDl9U50V6-RE
[total_amount] => 100
[send_listid] => 0010801705201512290383960635
[send_time] => 20151229152915
)
```
詳細示例:[/example/payment-coupon-cash.php](/example/payment-coupon-cash.php)