php知识总结

微信提现

2020-04-26  本文已影响0人  响呼雷
<?php
namespace wechatpay;

class WechatTiXian extends WechatRefund {

    //真实名字
    protected $truename = '';

    protected $openid;

    protected $order_sn;

    protected $money;

    protected $desc;

    public function __construct($openid,$order_sn,$money,$desc)
    {
        $this->openid = $openid;
        $this->order_sn = $order_sn;
        $this->money = $money;
        $this->desc = $desc;
        $this->apiclient_cert = ROOT_PATH . 'public' . DS . $this->SSLCERT_PATH;
        $this->apiclient_key = ROOT_PATH . 'public' . DS . $this->SSLKEY_PATH;
    }

    public function transfer()
    {
        //支付信息
        $webdata = array(
            'mch_appid' => $this->APPID,//商户账号appid
            'mchid' => $this->MCHID,//商户号
            'nonce_str' => $this->createNoncestr(),//随机字符串
            'partner_trade_no' => $this->order_sn, //商户订单号,需要唯一
            'openid' => $this->openid,//转账用户的openid
            're_user_name' => $this->truename,
            'check_name' => 'NO_CHECK', //OPTION_CHECK不强制校验真实姓名, FORCE_CHECK:强制 NO_CHECK:
            'amount' => $this->money * 100, //付款金额单位为分
            'desc' => $this->desc,//企业付款描述信息
            'spbill_create_ip' => $this->IP,//获取IP
        );
        foreach ($webdata as $k => $v) {
            $tarr[] = $k . '=' . $v;
        }
        sort($tarr);
        $sign = implode($tarr, '&');
        $sign .= '&key=' . $this->KEY;
        $webdata['sign'] = strtoupper(md5($sign));
        $wget = $this->arrayToXml($webdata);//数组转XML
        $res = $this->postData('https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers', $wget);//发送数据
        if (!$res) {
            return array('code' => 0, 'msg' => "不能连接到服务器");
        }
        $content = simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA);
        if (strval($content->return_code) == 'FAIL') {
            return array('code' => 0, 'msg' => strval($content->return_msg));
        }
        if (strval($content->result_code) == 'FAIL') {
            return array('code' => 0, 'msg' => strval($content->err_code_des));
        }
        $rdata = array(
            'mch_appid' => strval($content->mch_appid),
            'mchid' => strval($content->mchid),
            'device_info' => strval($content->device_info),
            'nonce_str' => strval($content->nonce_str),
            'result_code' => strval($content->result_code),
            'partner_trade_no' => strval($content->partner_trade_no),
            'payment_no' => strval($content->payment_no),
            'payment_time' => strval($content->payment_time),
        );
        return array('code' => 1, 'data' => $rdata);
    }
}
上一篇下一篇

猜你喜欢

热点阅读