<?php
/**
 * 企业付款
 */
include_once "WxPayPubHelper.php";
class EnterprisePayment extends Wxpay_client_pub
{
    function __construct() {
        //设置接口链接
        $this->url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
        //设置curl超时时间
        $this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;      
    }

    /**
     * 生成接口参数xml
     */
    function createXml()
    {
        try {
            //检测必填参数
            if ($this->parameters["partner_trade_no"] == null) {
                throw new SDKRuntimeException("退款申请接口中，缺少必填参数partner_trade_no！"."<br>");
            } elseif ($this->parameters["openid"] == null) {
                throw new SDKRuntimeException("退款申请接口中，缺少必填参数openid！"."<br>");
            } elseif ($this->parameters["amount"] == null) {
                throw new SDKRuntimeException("退款申请接口中，缺少必填参数amount！"."<br>");
            }
            $this->parameters["mch_appid"] = WxPayConf_pub::APPID;//公众账号ID
            $this->parameters["mchid"] = WxPayConf_pub::MCHID;//商户号
            $this->parameters["check_name"] = "NO_CHECK";//校验用户姓名选项 
            $this->parameters["desc"] = "分销提现";//企业付款描述信息 
            $this->parameters["spbill_create_ip"] = $_SERVER['REMOTE_ADDR'];//Ip地址 
            $this->parameters["nonce_str"] = $this->createNoncestr();//随机字符串
            $this->parameters["sign"] = $this->getSign($this->parameters);//签名
            return  $this->arrayToXml($this->parameters);
        } catch (SDKRuntimeException $e) {
            die($e->errorMessage());
        }
    }

    /**
     *  作用：获取结果，使用证书通信
     */
    function getResult()
    {       
        $this->postXmlSSL();
        $this->result = $this->xmlToArray($this->response);
        return $this->result;
    }
}