$value) { if ($key == "sign") { continue; } if ($value === "" || $value === null) { continue; } $dataStr .= $key . "=" . $value; $dataStr .= "&"; } return rtrim($dataStr, "&"); } public static function checkTradeType($authCode) { if (empty($authCode)) { return ""; } $prefix = substr($authCode, 0, 2); $aliPayCode = array("25", "26", "27", "28", "29", "30"); $wxPayCode = array("10", "11", "12", "13", "14", "15"); $unionPayCode = array("62"); if (in_array($prefix, $aliPayCode)) { return "alipay"; } else if (in_array($prefix, $wxPayCode)) { return "wxpay"; } else if (in_array($prefix, $unionPayCode)) { return "unionpay"; } return ""; } public static function dataRecodes($title, $data) { $handler = fopen('logs/result.txt', 'a+'); $content = "================" . $title . "===================\n"; if (is_string($data) === true) { $content .= $data . "\n"; } if (is_array($data) === true) { foreach ($data as $k => $v) { $content .= "key:【" . $k . "】,value: 【" . var_export($v, true) . "】\n"; } } $flag = fwrite($handler, $content); fclose($handler); return $flag; } /** * 调取支付 * @param string $URL * @param array $Params * @return bool|string */ public static function paymentOrder($URL=self::MICROPAY,$Params=[]) { $headers = array("Content-Type:application/json"); $config = [ 'org_code' => self::$org_code, 'mch_id' => self::$mch_id, 'version' => "1.0.0", 'charset' => "UTF-8", 'sign_type' => "RSA", 'pay_type' => 'wxpay', 'notify_url'=> sys_config('site_url')."/api/jialie/notify", ]; $requestParams = array_merge($config, $Params); $requestParams['sign'] = self::rsaSign($requestParams); $http = new HttpClient(); $http->setDebug(true); self::dataRecodes('付款码支付request报文 ', $requestParams); $rs = $http->post(self::$Url.$URL,json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),$headers); //$rs = self::http(self::$Url.$URL,"POST",json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),$headers); self::dataRecodes('付款码支付response报文 ', self::$Url.$URL.'--'.json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); self::dataRecodes('付款码支付response报文 ', $rs); return $rs; } public static function paymentquery($URL=self::QUERY,$Params) { $headers = array("Content-Type:application/json"); $config = [ 'org_code' => self::$org_code, 'mch_id' => self::$mch_id, 'version' => "1.0.0", 'charset' => "UTF-8", 'sign_type' => "RSA", ]; $requestParams = array_merge($config, $Params); $requestParams['sign'] = self::rsaSign($requestParams); $http = new HttpClient(); //$http->setDebug(true); //self::dataRecodes('订单查询request报文 ', $requestParams); $rs = $http->post(self::$Url.$URL,json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),$headers); //$rs = self::http(self::$Url.$URL,"POST",json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),$headers); //self::dataRecodes('订单查询response报文 ', self::$Url.$URL.'--'.json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); //self::dataRecodes('订单查询response报文 ', $rs); return $rs; } public static function payOrderRefund($orderNo, array $opt) { if (!isset($opt['pay_price'])) exception('缺少pay_price'); $totalFee = floatval(bcmul($opt['pay_price'], 100, 0)); $refundFee = isset($opt['refund_price']) ? floatval(bcmul($opt['refund_price'], 100, 0)) : null; $refundReason = isset($opt['desc']) ? $opt['desc'] : ''; $headers = array("Content-Type:application/json"); $config = [ 'org_code' => self::$org_code, 'mch_id' => self::$mch_id, 'charset' => "UTF-8", 'sign_type' => "RSA", ]; $Params['nonce_str'] = uniqid(); $Params['out_trade_no'] = 'ref'.uniqid(); $Params['ori_out_trade_no'] = $orderNo; $Params['total_fee'] = intval($refundFee); $Params['mch_create_ip'] = app('request')->ip(); $Params['remark'] = $refundReason; $requestParams = array_merge($config, $Params); $requestParams['sign'] = self::rsaSign($requestParams); $http = new HttpClient(); $http->setDebug(true); self::dataRecodes('订单退款request报文 ', $requestParams); $rs = $http->post(self::$Url.self::REFUND,json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),$headers); //$rs = self::http(self::$Url.$URL,"POST",json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),$headers); self::dataRecodes('订单退款request报文 ', self::$Url.self::REFUND.'--'.json_encode($requestParams, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); self::dataRecodes('订单退款request报文 ', $rs); return $rs; } }