'yp_account', 'type' => 'text', 'value' => ''), array('name' => 'yp_key', 'type' => 'text', 'value' => ''), ); return; } /** * 类 */ class yeepay_cmbchina { /** * 构造函数 * * @access public * @param * * @return void */ function yeepay_cmbchina() { $this->frpid = 'CMBCHINA-NET'; } function __construct() { $this->yeepay_cmbchina(); } /** * 生成支付代码 * @param array $order 订单信息 * @param array $payment 支付方式信息 */ function get_code($order, $payment) { $data_merchant_id = $payment['yp_account']; $data_order_id = $order['order_sn']; $data_amount = $order['order_amount']; $message_type = 'Buy'; $data_cur = 'CNY'; $product_id = ''; $product_cat = ''; $product_desc = ''; $address_flag = '0'; $data_return_url = return_url(basename(__FILE__, '.php')); $data_pay_key = $payment['yp_key']; $data_pay_account = $payment['yp_account']; $mct_properties = $order['log_id']; $def_url = $message_type . $data_merchant_id . $data_order_id . $data_amount . $data_cur . $product_id . $product_cat . $product_desc . $data_return_url . $address_flag . $mct_properties . $this->frpid; $MD5KEY = hmac($def_url, $data_pay_key); $def_url = "\n
\n"; return $def_url; } /** * 响应操作 */ function respond() { $payment = get_payment('yeepay_cmbchina'); $merchant_id = $payment['yp_account']; // 获取商户编号 $merchant_key = $payment['yp_key']; // 获取秘钥 $message_type = trim($_REQUEST['r0_Cmd']); $succeed = trim($_REQUEST['r1_Code']); // 获取交易结果,1成功,-1失败 $trxId = trim($_REQUEST['r2_TrxId']); $amount = trim($_REQUEST['r3_Amt']); // 获取订单金额 $cur = trim($_REQUEST['r4_Cur']); // 获取订单货币单位 $product_id = trim($_REQUEST['r5_Pid']); // 获取产品ID $orderid = trim($_REQUEST['r6_Order']); // 获取订单ID $userId = trim($_REQUEST['r7_Uid']); // 获取产品ID $merchant_param = trim($_REQUEST['r8_MP']); // 获取商户私有参数 $bType = trim($_REQUEST['r9_BType']); // 获取订单ID $mac = trim($_REQUEST['hmac']); // 获取安全加密串 ///生成加密串,注意顺序 $ScrtStr = $merchant_id . $message_type . $succeed . $trxId . $amount . $cur . $product_id . $orderid . $userId . $merchant_param . $bType; $mymac = hmac($ScrtStr, $merchant_key); $v_result = false; if (strtoupper($mac) == strtoupper($mymac)) { if ($succeed == '1') { ///支付成功 $v_result = true; $order_id = str_replace($orderid, '', $product_id); order_paid($merchant_param); } } return $v_result; } } if (!function_exists("hmac")) { function hmac($data, $key) { // RFC 2104 HMAC implementation for php. // Creates an md5 HMAC. // Eliminates the need to install mhash to compute a HMAC // Hacked by Lance Rushing(NOTE: Hacked means written) $key = ecs_iconv('GB2312', 'UTF8', $key); $data = ecs_iconv('GB2312', 'UTF8', $data); $b = 64; // byte length for md5 if (strlen($key) > $b) { $key = pack('H*', md5($key)); } $key = str_pad($key, $b, chr(0x00)); $ipad = str_pad('', $b, chr(0x36)); $opad = str_pad('', $b, chr(0x5c)); $k_ipad = $key ^ $ipad ; $k_opad = $key ^ $opad; return md5($k_opad . pack('H*', md5($k_ipad . $data))); } } ?>