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HmL033hT98CgYEA1BfqAGtImXcJ9EfcAHF/6cow6isc+yzKzpGw5v9S2la08gZrCdVtBdypHCB2J3NFHCypLRvbsQRsVGfIC8P+ddeisarmrccZmMaRgGmk/jBO3O3YrTNQ1/djdH1IwuieCqvpBHQY12GGtNEHXOBOhiXOvc/BJFuYRuIONTP/Hc8CgYAzUDumMRlFTLUfYNIX6tK3PvkXVe2ptvz+mShprPAAzcp+u/t8oXo53BqSaeLoMf7ypbdFbim2O7ZKjWzFc5sL6lhNHyqoOYxhsZGc3LaREeq+fU0/YJMc/omAPrRXxJWG3Ak13buPGPMeY9mVoQsZ8Yd7c0Aj7oYA1DMqMYwD0wKBgEenuZbJDJFOXgRj9T7UvE2ANvnZtCLNhxlQ+AtCCSKTUSESQvO2v+Xhe2bKYhZAejXBykia2UjUDmeDVzT2aID0p+qLaAUtfOdR2ahUN4ME0JJFcwzqSODeuOR7CqWWDu2OQ/rJMhh12nePzMpedepkRrGnzqBwPljAPnigat04'; $this->aliPayRsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhkW8tpvdkVRZklapB+scLgcdL6N8/noWdV4h6ViUDxHd1rSjYJRHLmFgLYLgyKHHyS3tXySPf7qRbWwyImV4A17+WNTxAtdMH+TBAuqS49sAND4JYjurtY6CbQjwBEHUOE506DhISM4+fzkgtLGF8lD0jAJyXFRK4XutL3ddJ2XSzbIUTvT1bIP+cwNQcsmTTmpO145+9gKvx8tkHILKZPockarsoUoeo9gapB3hnNHNrYTbzpsa/zkOETD7L3rgpWbGJSc675t5dk8RaqH13Eon0BTn/Ov5gJ0P8j4VUWXYqdI9cEVur65S002vvhiIFVpy+30nB9SviF+/rcjQnQIDAQAB'; } /* * 支付宝支付 */ public function aliPay($body, $total_amount, $product_code, $notify_url) { /** * 调用支付宝接口。 */ $isdir = dirname(__DIR__)."/library/";//绝对路径 require_once($isdir.'/alipay/aop/AopClient.php'); require_once($isdir.'/alipay/aop/request/AlipayTradeAppPayRequest.php'); $total_amount = floatval($total_amount); $aop = new AopClient(); $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; $aop->appId = $this->appId; $aop->rsaPrivateKey = $this->rsaPrivateKey; $aop->format = "json"; $aop->charset = "UTF-8"; $aop->signType = "RSA2"; $aop->alipayrsaPublicKey = $this->aliPayRsaPublicKey; $request = new AlipayTradeAppPayRequest(); $arr['body'] = $body; $arr['subject'] = $body; $arr['out_trade_no'] = $product_code; $arr['timeout_express'] = '30m'; $arr['total_amount'] = $total_amount; $arr['product_code'] = 'QUICK_MSECURITY_PAY'; $json = json_encode($arr); $request->setNotifyUrl($notify_url); $request->setBizContent($json); $response = $aop->sdkExecute($request); return $response; } //支付宝退款 public function zfbrefund($out_trade_no,$out_refund_no,$total_fee,$refund_reason){ $total_fee = sprintf("%.2f",substr(sprintf("%.4f", $total_fee), 0, -2)); $isdir = dirname(__DIR__)."/library/";//绝对路径 require_once($isdir.'/alipay/aop/AopClient.php'); require_once($isdir.'/alipay/aop/request/AlipayTradeRefundRequest.php'); $aop = new AopClient(); $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; $aop->appId = $this->appId; $aop->rsaPrivateKey = $this->rsaPrivateKey; $aop->format = "json"; $aop->charset = "UTF-8"; $aop->signType = "RSA2"; $aop->apiVersion = '1.0'; // $aop->alipayrsaPublicKey = $this->aliPayRsaPublicKey; $request = new \AlipayTradeRefundRequest(); //$arr['trade_no'] = $out_refund_no; $arr['out_trade_no'] = $out_trade_no; $arr['refund_amount'] = $total_fee; $arr['refund_reason'] = $refund_reason; $arr['refund_currency'] = "CNY"; $arr['operator_id'] = "OP001"; $arr['store_id'] = "NJ_S_001"; $arr['terminal_id'] = "NJ_T_001"; $json = json_encode($arr); $request->setBizContent($json); $result = $aop->execute($request); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $resultCode = $result->$responseNode->code; return $resultCode; } //支付宝转账个人账户 public function FundTransToaccount($out_trade_no,$account,$account_real_name,$amount,$remark){ $amount = sprintf("%.2f",substr(sprintf("%.4f", $amount), 0, -2)); $isdir = dirname(__DIR__)."/library/";//绝对路径 require_once($isdir.'/alipay/aop/AopClient.php'); $aop = new AopClient(); $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; $aop->appId = $this->appId; $aop->rsaPrivateKey = $this->rsaPrivateKey; $aop->format = 'json'; $aop->charset = 'UTF-8'; $aop->signType = 'RSA2'; //$aop->alipayrsaPublicKey = $this->aliPayRsaPublicKey; require_once($isdir.'/alipay/aop/request/AlipayFundTransToaccountTransferRequest.php'); $request = new \AlipayFundTransToaccountTransferRequest(); $arr['out_biz_no'] = $out_trade_no; //订单号 $arr['payee_type'] = 'ALIPAY_LOGONID'; $arr['payee_account'] = $account; //对方支付宝账号 $arr['payee_real_name'] = $account_real_name; //支付宝实名姓名 $arr['amount'] = $amount; $arr['remark'] = $remark; $json = json_encode($arr,true); $request->setBizContent($json); $result = $aop->execute($request); $result2 = json_decode(json_encode($result),true); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $resultCode = $result->$responseNode->code; $arr = ['code'=>$resultCode,'result'=>$result2]; return $arr; } function createLinkstring($para) { $arg = ""; while (list ($key, $val) = each($para)) { $arg .= $key . "=" . $val . "&"; } //去掉最后一个&字符 $arg = substr($arg, 0, count($arg) - 2); //如果存在转义字符,那么去掉转义 if (get_magic_quotes_gpc()) { $arg = stripslashes($arg); } return $arg; } function argSort($para) { ksort($para); reset($para); return $para; } }