Ejemplo n.º 1
0
function customHttpClient($SERVER, $PATH, $COOKIES, $PARAMS)
{
    //return;//return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败"}}';
    //到远程服务器查询登录状态
    include_once dirname(__FILE__) . '/httpclient.inc.php';
    try {
        $client = new HttpClient($SERVER);
        $client->timeout = 10;
        $client->setCookies($COOKIES);
        $client->setPersistCookies(true);
        $postURL = $PATH;
        customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", getHexDecode($client->buildQueryString($PARAMS)));
        if (!$client->post($postURL, $PARAMS)) {
            customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nFAILD1");
            return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败1"}}';
        }
    } catch (Exception $e) {
        customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nFAILD2");
        return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败2"}}';
    }
    $response = $client->getContent();
    customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nPUT COOKIES:" . (is_array($COOKIES) ? var_export($COOKIES, true) : '') . "\nPUT DATA:" . (is_array($PARAMS) ? var_export($PARAMS, true) : $PARAMS) . "\nGET DATA:" . iconv('GBK', 'UTF-8', $response));
    return iconv('GBK', 'UTF-8', $response);
}
Ejemplo n.º 2
0
function eposSale(array $bizArray, $actionURL, $merchantKey, $logName)
{
    // 调用签名函数生成签名串
    $ReqHmacString = getReqHmacString($bizArray, $logName, $merchantKey);
    // 组成请求串
    $actionHttpString = HttpClient::buildQueryString($bizArray) . "&pr_NeedResponse=1" . "&hmac=" . $ReqHmacString;
    // echo $actionURL."?".$actionHttpString;exit;
    // 记录发起支付请求的参数
    logurl("发起请求", $actionURL . "?" . $actionHttpString, $logName);
    // 发起支付请求
    $pageContents = HttpClient::quickPost($actionURL, $actionHttpString);
    if ($GLOBALS['uid'] == '20310462') {
        echo $pageContents . "<br>";
    }
    // 记录收到的提交结果
    logurl("请求回写", $pageContents, $logName);
    $result = explode("\n", $pageContents);
    for ($index = 0; $index < count($result); $index++) {
        $result[$index] = trim($result[$index]);
        if (strlen($result[$index]) == 0) {
            continue;
        }
        $aryReturn = explode("=", $result[$index]);
        $sKey = $aryReturn[0];
        $sValue = $aryReturn[1];
        if ($sKey == "r0_Cmd") {
            $r0_Cmd = $sValue;
        } elseif ($sKey == "r1_Code") {
            $r1_Code = $sValue;
        } elseif ($sKey == "r2_TrxId") {
            $r2_TrxId = $sValue;
        } elseif ($sKey == "r6_Order") {
            $r6_Order = $sValue;
        } elseif ($sKey == "errorMsg") {
            $errorMsg = $sValue;
        } elseif ($sKey == "hmac") {
            $hmac = $sValue;
        }
        /* else{
        		   return $result[$index];
        		}   */
    }
    $hmac = iconv("UTF-8", "GB2312", $hmac);
    // 进行校验码检查 取得加密前的字符串
    $sbOld = "";
    // 加入业务类型
    $sbOld = $sbOld . $r0_Cmd;
    // 加入支付结果
    $sbOld = $sbOld . $r1_Code;
    // 加入易宝支付交易流水号
    $sbOld = $sbOld . $r2_TrxId;
    // 加入商户订单号
    $sbOld = $sbOld . $r6_Order;
    $sNewString = HmacMd5($sbOld, $merchantKey, $logName);
    logurl("订单号:" . $r6_Order, "本地生成HMAC:" . $sNewString . "返回HMAC:" . $hmac, $logName);
    $uid = substruid($r6_Order, 14);
    $money = $bizArray['p3_Amt'];
    global $_MooClass, $dbTablePre;
    $sql_getpayid = "SELECT max(id) id FROM {$dbTablePre}payment_new WHERE order_id='{$r6_Order}'";
    $getpayid = $_MooClass['MooMySQL']->getOne($sql_getpayid, true);
    $id = $getpayid['id'];
    $sql_p = "SELECT pay_service FROM {$dbTablePre}payment_new WHERE id='{$id}'";
    $payservice = $_MooClass['MooMySQL']->getOne($sql_p, true);
    //	if($money=='1899'){
    //		$attach='0';
    //	}elseif($money=='1399'){
    //		$attach='1';
    //	}elseif($money=='1399.00'){
    //		$attach='2';
    //	}else{
    //		$attach='1';
    //	}
    //
    if ($payservice['pay_service'] == '0') {
        $attach = '0';
    } elseif ($payservice['pay_service'] == '1' || $payservice['pay_service'] == '3') {
        $attach = '1';
    } elseif ($payservice['pay_service'] == '2') {
        $attach = '2';
    } else {
        $attach = '1';
    }
    if ($GLOBALS['uid'] == '20310462') {
        echo $sNewString;
        exit;
    }
    // 校验码正确
    if ($sNewString == $hmac) {
        if ($r1_Code == "1") {
            logurl("请求成功", "本地生成HMAC:" . $sNewString . "返回HMAC:" . $hmac, $logName);
            //返回信息 数组表示
            $paytime = date("Y.m.d H:i:s");
            $payurl = array('pay' => '1', 'out_trade_no' => $r6_Order, 'paytime' => $paytime, 'bank_type' => '易宝支付', 'trade_state' => '0', 'get_img' => '05.gif', 'img' => $attach, 'total_fee' => $bizArray['p3_Amt'], 'uid' => $uid);
            //会员ID
            $payurl = implode(',', $payurl);
            $payurl = $payurl . ',yeepay';
            header("Location:./../../index.php?n=payment&h=payreturnurl&payurl=" . $payurl);
            return;
        } elseif ($r1_Code == "66") {
            $errorinfo = iconv("GB2312", "UTF-8", "订单金额过小!");
        } elseif ($r1_Code == "30001") {
            $errorinfo = iconv("GB2312", "UTF-8", "填写信息格式有误!");
        } elseif ($r1_Code == "3002") {
            $errorinfo = iconv("GB2312", "UTF-8", "创建订单异常!");
        } elseif ($r1_Code == "3003") {
            $errorinfo = iconv("GB2312", "UTF-8", "创建交易异常!");
        } elseif ($r1_Code == "3006") {
            $errorinfo = iconv("GB2312", "UTF-8", "提交失败!银行返回失败信息:{$errorMsg}!");
        } elseif ($r1_Code == "3008") {
            $errorinfo = iconv("GB2312", "UTF-8", "卡号规则不符合!");
        } elseif ($r1_Code == "3009") {
            $errorinfo = iconv("GB2312", "UTF-8", "卡号有误或不支持的银行!");
        } elseif ($r1_Code == "3010") {
            $errorinfo = iconv("GB2312", "UTF-8", "查询信用卡类型出错!");
        } elseif ($r1_Code == "3011") {
            $errorinfo = iconv("GB2312", "UTF-8", "日期格式错误!");
        } elseif ($r1_Code == "-100") {
            $errorinfo = iconv("GB2312", "UTF-8", "未知错误!");
        } else {
            $errorinfo = iconv("GB2312", "UTF-8", "提交失败,请检查后重新测试支付!");
        }
        $trade_state = '1';
        $payurl = array('pay' => '3', 'errorinfo' => $errorinfo, 'trade_state' => $trade_state);
        $payurl = implode(',', $payurl);
        $payurl = $payurl . ',yeepay';
        header("Location:./../../index.php?n=payment&h=payreturnurl&payurl=" . $payurl);
        exit;
    } else {
        $trade_state = '1';
        $errorinfo = iconv("GB2312", "UTF-8", "服务器出错!");
        $payurl = array('pay' => '3', 'errorinfo' => $errorinfo, 'trade_state' => $trade_state);
        $payurl = implode(',', $payurl);
        $payurl = $payurl . ',yeepay';
        header("Location:./../../index.php?n=payment&h=payreturnurl&payurl=" . $payurl);
        exit;
    }
}