Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信支付-》企业付款也可以增加个类上去,跟企业红包类似 #232

Closed
vcanson opened this issue Jan 10, 2016 · 0 comments

Comments

@vcanson
Copy link

vcanson commented Jan 10, 2016

class EntMoney
{
/**
* 企业发送现金
*/
const API_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';

public function send(array $data)
{
    $defaultParam['nonce_str'] = uniqid('pre_');
    $defaultParam['mchid'] = $this->business->mch_id;
    $defaultParam['mch_appid'] = $this->business->appid;

    //if ($type == self::TYPE_CASH_LUCK_MONEY) {
        $defaultParam['spbill_create_ip'] = $_SERVER['REMOTE_ADDR'];
    //}

    $defaultParam['check_name']='NO_CHECK';

    $param = array_merge($data, $defaultParam);
    $signGenerator = new SignGenerator($param);
    $me = $this;
    $signGenerator->onSortAfter(function (SignGenerator $that) use ($me) {
        $that->key = $me->business->mch_key;
    });

    $sign = $signGenerator->getResult();
    $param['sign'] = $sign;

    $request = XML::build($param);

    //设置Http使用的证书
    $options['sslcert_path'] = $this->business->getClientCert();
    $options['sslkey_path'] = $this->business->getClientKey();

    $http = new Http();


        $url = self::API_SEND;

    $response = $http->request($url, Http::POST, $request, $options);

    if (empty($response)) {
        throw new Exception('Send LuckMoney failed.');
    }

    $result = XML::parse($response);

    return $result;
}

/使用/
$business = new Business(
Config::get('wechat.app_id'),
Config::get('wechat.secret'),
Config::get('wechat.mch_id'),
Config::get('wechat.mch_key')
);
$business->setClientCert(Config::get('wechat.clientcert_path'));
$business->setClientKey(Config::get('wechat.clientkey_path'));

    $entMoney = new EntMoney($business);

    $entMoneyData['partner_trade_no'] = time();  //订单号
    $entMoneyData['openid'] = $custom->openid;  //企业付款接收者的openId
    $entMoneyData['check_name'] = 'NO_CHECK';  //是否核对真实姓名
    $entMoneyData['amount'] = floor($money);  //支付现金
    $entMoneyData['desc'] = '奖金支付给A企业员工';

    $result = $entMoney->send($entMoneyData);   
@vcanson vcanson closed this as completed Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant