'KP10008973', "timestamp" => time(), "nonce_str" => $randsi, "sign_type" => 'MD5', "content" => json_encode([ "client_ip" => Request::instance()->ip(), "out_trade_no" => $orderid, "fee" => $real_amount * 100,//0.01 "body" => '南京倾枫充值', "open_id" => '', "notify_url" => $notify_url, "return_url" => $return_url, ]), ]; foreach (array_filter($array) as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $buff = ""; ksort($Parameters); foreach ($Parameters as $k => $v) { $buff .= $k . "=" . $v . "&"; } $String = ''; if (strlen($buff) > 0) { $String = substr($buff, 0, strlen($buff) - 1); } $String = $String . "&secret_key=" . 'psVr7sLJHNLNK7XEQrPKNBszbQaeHko6'; //签名步骤三:MD5加密 $String = md5($String); //签名步骤四:所有字符转为大写 $strings = strtoupper($String); $array['sign'] = $strings; $res = json_decode(self::http_post('https://pay.kudianvip.com/openapi/pay/kdh5pay', json_encode($array)), true); if ($res['code'] != 0) { return '错误信息为:' . $res['msg']; } //返回参数格式设计 if (!empty($res['result'])) { $res_data = json_decode($res['result'], true); if (!empty($res_data)) { $rs = $res_data['url']; return $rs; } else { return '错误信息为:' . $res['msg']; } } else { return '错误信息为:' . $res['msg']; } } /** * 酷点扫码支付 * @param $body * @param $orderid * @param $real_amount * @param string $return_url * @param string $notify_url * @return mixed|string */ function oil_fee_sm_get($body, $orderid, $real_amount, $return_url = '', $notify_url = '') { $randsi = date("YmdHis") . date("YmdHis") . rand(1000, 9999); $array = [ "mch_id" => 'KP10008973', "timestamp" => time(), "nonce_str" => $randsi, "sign_type" => 'MD5', "content" => json_encode([ "payment" => 'WXPAY', 'trade_type' => 'SCANCODE', "client_ip" => Request::instance()->ip(), "out_trade_no" => $orderid, "fee" => $real_amount * 100,//0.01 "body" => '南京倾枫充值', "open_id" => '', "notify_url" => $notify_url, "sence_info" => [ "return_url" => $return_url, ] // "return_url"=>$return_url, ]), ]; foreach (array_filter($array) as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $buff = ""; ksort($Parameters); foreach ($Parameters as $k => $v) { $buff .= $k . "=" . $v . "&"; } $String = ''; if (strlen($buff) > 0) { $String = substr($buff, 0, strlen($buff) - 1); } $String = $String . "&secret_key=" . 'psVr7sLJHNLNK7XEQrPKNBszbQaeHko6'; //签名步骤三:MD5加密 $String = md5($String); //签名步骤四:所有字符转为大写 $strings = strtoupper($String); $array['sign'] = $strings; $res = json_decode(self::http_post('https://pay.kudianvip.com/openapi/pay/unifiedpay', json_encode($array)), true); if ($res['code'] != 0) { return '错误信息为:' . $res['msg']; } //返回参数格式设计 if (!empty($res['result'])) { $res_data = json_decode($res['result'], true); if (!empty($res_data) && $res_data['status'] == 0) { $rs = $res_data['pay_info']['url']; return $rs; } else { return '错误信息为:' . $res['msg']; } } else { return '错误信息为:' . $res['msg']; } } function notifyVerify($data) { unset($data['sign']); foreach ($data as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $buff = ""; ksort($Parameters); foreach ($Parameters as $k => $v) { $buff .= $k . "=" . $v . "&"; } $String = ''; if (strlen($buff) > 0) { $String = substr($buff, 0, strlen($buff) - 1); } $String = $String . "&secret_key=" . 'psVr7sLJHNLNK7XEQrPKNBszbQaeHko6'; //签名步骤三:MD5加密 $String = md5($String); //签名步骤四:所有字符转为大写 $strings = strtoupper($String); return $strings; } public function queryOrder($order_no) { $randsi = date("YmdHis") . date("YmdHis") . rand(1000, 9999); $array = [ "mch_id" => 'KP10008973', "timestamp" => time(), "nonce_str" => $randsi, "sign_type" => 'MD5', "content" => json_encode([ "out_trade_no" => $order_no, ]), ]; foreach (array_filter($array) as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $buff = ""; ksort($Parameters); foreach ($Parameters as $k => $v) { $buff .= $k . "=" . $v . "&"; } $String = ''; if (strlen($buff) > 0) { $String = substr($buff, 0, strlen($buff) - 1); } $String = $String . "&secret_key=" . 'psVr7sLJHNLNK7XEQrPKNBszbQaeHko6'; //签名步骤三:MD5加密 $String = md5($String); //签名步骤四:所有字符转为大写 $strings = strtoupper($String); $array['sign'] = $strings; $res = json_decode(self::http_post('https://pay.kudianvip.com/openapi/pay/query', json_encode($array)), true); $res_data = json_decode($res, true); //对响应结果进行验签,具体见下面的验签示例 if ($res_data['msg'] == 'SUCCESS') { return $res_data; echo '验签成功'; } else { echo '验签失败'; return false; } } /** * 使用http_post提交 * @param $url * @param $params * @param bool $contentType * @return bool|mixed|string */ function GetRandStr($length) { //字符组合 $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $len = strlen($str) - 1; $randstr = ''; for ($i = 0; $i < $length; $i++) { $num = mt_rand(0, $len); $randstr .= $str[$num]; } return $randstr; } /** * 使用http_post提交 * @param $url * @param $params * @param bool $contentType * @return bool|mixed|string */ protected function http_post($url, $params, $contentType = true) { if (function_exists('curl_init')) { // curl方式 $oCurl = curl_init(); if (stripos($url, 'https://') !== FALSE) { curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE); } $string = $params; if (is_array($params)) { $aPOST = array(); foreach ($params as $key => $val) { $aPOST[] = $key . '=' . urlencode($val); } $string = join('&', $aPOST); } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($oCurl, CURLOPT_POST, TRUE); //$contentType json处理 if ($contentType) { $headers = array( "Content-type: application/json;charset='utf-8'", ); curl_setopt($oCurl, CURLOPT_HTTPHEADER, $headers); // echo $params; curl_setopt($oCurl, CURLOPT_POSTFIELDS, $params); } else { curl_setopt($oCurl, CURLOPT_POSTFIELDS, $string); } $response = curl_exec($oCurl); curl_close($oCurl); return $response; } elseif (function_exists('stream_context_create')) { // php5.3以上 $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($params), ) ); $_opts = stream_context_get_params(stream_context_get_default()); $context = stream_context_create(array_merge_recursive($_opts['options'], $opts)); return file_get_contents($url, false, $context); } else { return FALSE; } } }