private function getSign($type, $data) { $md5str = ""; switch ($type) { case "gfb": $signarray = array("version", "tranCode", "merchantID", "merOrderNum", "tranAmt", "feeAmt", "tranDateTime", "frontMerUrl", "backgroundMerUrl", "orderId", "gopayOutOrderId", "tranIP", "respCode", "gopayServerTime"); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= "{$v}=[]"; } else { $md5str .= "{$v}=[{$data[$v]}]"; } } $md5str .= "VerficationCode=[" . $this->payConfig['guofubao']['VerficationCode'] . "]"; $md5str = md5($md5str); return $md5str; break; case "ips": $md5str = "billno" . $data['Billno'] . "currencytype" . $data['Currency_Type'] . "amount" . $data['Amount'] . "date" . $data['Date'] . "orderencodetype" . $data['OrderEncodeType']; $md5str .= $this->payConfig['ips']['MerKey']; $md5str = md5($md5str); return $md5str; break; case "ips_return": $md5str = "billno" . $data['billno'] . "currencytype" . $data['Currency_type'] . "amount" . $data['amount'] . "date" . $data['date'] . "succ" . $data['succ'] . "ipsbillno" . $data['ipsbillno'] . "retencodetype" . $data['retencodetype']; $md5str .= $this->payConfig['ips']['MerKey']; $md5str = md5($md5str); return $md5str; break; case "chinabank": $signarray = array("v_amount", "v_moneytype", "v_oid", "v_mid", "v_url"); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['chinabank']['mkey']; $md5str = md5($md5str); return $md5str; break; case "chinabank_return": $signarray = array("v_oid", "v_pstatus", "v_amount", "v_moneytype"); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['chinabank']['mkey']; $md5str = md5($md5str); return $md5str; break; /*case "baofoo"://老宝付支付接口 $signarray = array( "MerchantID", "PayID", "TradeDate", "TransID", "OrderMoney", "Merchant_url", "Return_url", "NoticeType" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break; case "baofoo_return": $signarray = array( "MerchantID", "TransID", "Result", "resultDesc", "factMoney", "additionalInfo", "SuccTime" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break;*/ /*case "baofoo"://老宝付支付接口 $signarray = array( "MerchantID", "PayID", "TradeDate", "TransID", "OrderMoney", "Merchant_url", "Return_url", "NoticeType" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break; case "baofoo_return": $signarray = array( "MerchantID", "TransID", "Result", "resultDesc", "factMoney", "additionalInfo", "SuccTime" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break;*/ case "baofoo": $signarray = array("MemberID", "PayID", "TradeDate", "TransID", "OrderMoney", "PageUrl", "ReturnUrl", "NoticeType"); foreach ($signarray as $v) { $md5str .= $data[$v] . '|'; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5($md5str); return $md5str; break; case "baofoo_return": $signarray = array("MemberID", "TerminalID", "TransID", "Result", "ResultDesc", "FactMoney", "AdditionalInfo", 'SuccTime'); foreach ($signarray as $v) { $md5str .= "{$v}" . '=' . $data[$v] . '~|~'; } //dump($md5str); $md5str .= 'Md5Sign=' . $this->payConfig['baofoo']['pkey']; $md5str = md5($md5str); return $md5str; break; case "shengpay": $signarray = array('Name', 'Version', 'Charset', 'MsgSender', 'SendTime', 'OrderNo', 'OrderAmount', 'OrderTime', 'PayType', 'PageUrl', 'NotifyUrl', 'ProductName', 'BuyerContact', 'BuyerIp', 'Ext1', 'Ext2', 'SignType'); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['shengpay']['pkey']; //MD5密钥 $md5str = strtoupper(md5($md5str)); return $md5str; break; case "shengpay_return": $signarray = array('Name', 'Version', 'Charset', 'TraceNo', 'MsgSender', 'SendTime', 'InstCode', 'OrderNo', 'OrderAmount', 'TransNo', 'TransAmount', 'TransStatus', 'TransType', 'TransTime', 'MerchantNo', 'ErrorCode', 'ErrorMsg', 'Ext1', 'Ext2', 'SignType'); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['shengpay']['mkey']; $md5str = strtoupper(md5($md5str)); return $md5str; break; case "tenpay": $signPars = ""; ksort($data); foreach ($data as $k => $v) { if ("" != $v && "sign" != $k) { $signPars .= $k . "=" . $v . "&"; } } $signPars .= "key=" . $this->payConfig['tenpay']['key']; $md5str = strtoupper(md5($signPars)); return $md5str; break; case "ecpss": $signarray = array('MerNo', 'BillNo', 'Amount', 'ReturnURL'); //校验源字符串 foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= $data[$v] . '&'; } } $md5str .= $this->payConfig['ecpss']['MD5key']; //MD5密钥 //exit($md5str); $md5str = strtoupper(md5($md5str)); return $md5str; break; case "ecpss_return": $signarray = array("BillNo", "Amount", "Succeed"); //校验源字符串 foreach ($signarray as $v) { $md5str .= $data[$v] . "&"; } $md5str .= $this->payConfig['ecpss']['MD5key']; $md5str = strtoupper(md5($md5str)); return $md5str; break; case "easypay": //易生支付 $para = array(); while (list($key, $val) = each($data)) { if ($key == "sign" || $key == "sign_type" || $val == "") { continue; } else { $para[$key] = $data[$key]; } } ksort($para); reset($para); $signPars = ""; while (list($key, $val) = each($para)) { $signPars .= $key . "=" . $val . "&"; } $signPars = substr($signPars, 0, count($signPars) - 2); //去掉最后一个&字符 $signPars .= $this->payConfig['easypay']['key']; $md5str = md5($signPars); return $md5str; break; case "cmpay": //中国移动 $signarray = array('merchantId', 'payNo', 'returnCode', 'message', 'signType', 'type', 'version', 'amount', 'amtItem', 'bankAbbr', 'mobile', 'orderId', 'payDate', 'accountDate', 'reserved1', 'reserved2', 'status', 'orderDate', 'fee'); foreach ($signarray as $v) { $mac .= $data[$v]; } $signKey = $this->payConfig['cmpay']['serverCert']; $mac = MD5sign($signKey, $mac); return $mac; break; case "cmpay_return": //中国移动 foreach ($data as $v) { $mac .= $v; } $signKey = $this->payConfig['cmpay']['serverCert']; //MD5方式签名 $hmac = MD5sign($signKey, $mac); return $hmac; break; } }
private function getSign($type, $data) { $md5str = ""; switch ($type) { case "gfb": $signarray = array("version", "tranCode", "merchantID", "merOrderNum", "tranAmt", "feeAmt", "tranDateTime", "frontMerUrl", "backgroundMerUrl", "orderId", "gopayOutOrderId", "tranIP", "respCode", "gopayServerTime"); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= "{$v}=[]"; } else { $md5str .= "{$v}=[{$data[$v]}]"; } } $md5str .= "VerficationCode=[" . $this->payConfig['guofubao']['VerficationCode'] . "]"; $md5str = md5($md5str); return $md5str; break; case "ips": $md5str = "billno" . $data['Billno'] . "currencytype" . $data['Currency_Type'] . "amount" . $data['Amount'] . "date" . $data['Date'] . "orderencodetype" . $data['OrderEncodeType']; $md5str .= $this->payConfig['ips']['MerKey']; $md5str = md5($md5str); return $md5str; break; case "ips_return": $md5str = "billno" . $data['billno'] . "currencytype" . $data['Currency_type'] . "amount" . $data['amount'] . "date" . $data['date'] . "succ" . $data['succ'] . "ipsbillno" . $data['ipsbillno'] . "retencodetype" . $data['retencodetype']; $md5str .= $this->payConfig['ips']['MerKey']; $md5str = md5($md5str); return $md5str; break; case "chinabank": $signarray = array("v_amount", "v_moneytype", "v_oid", "v_mid", "v_url"); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['chinabank']['mkey']; $md5str = md5($md5str); return $md5str; break; case "chinabank_return": $signarray = array("v_oid", "v_pstatus", "v_amount", "v_moneytype"); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['chinabank']['mkey']; $md5str = md5($md5str); return $md5str; break; /*case "baofoo"://老宝付支付接口 $signarray = array( "MerchantID", "PayID", "TradeDate", "TransID", "OrderMoney", "Merchant_url", "Return_url", "NoticeType" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break; case "baofoo_return": $signarray = array( "MerchantID", "TransID", "Result", "resultDesc", "factMoney", "additionalInfo", "SuccTime" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break;*/ /*case "baofoo"://老宝付支付接口 $signarray = array( "MerchantID", "PayID", "TradeDate", "TransID", "OrderMoney", "Merchant_url", "Return_url", "NoticeType" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break; case "baofoo_return": $signarray = array( "MerchantID", "TransID", "Result", "resultDesc", "factMoney", "additionalInfo", "SuccTime" ); foreach ( $signarray as $v ) { $md5str .= $data[$v]; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5( $md5str ); return $md5str; break;*/ case "baofoo": $signarray = array("MemberID", "PayID", "TradeDate", "TransID", "OrderMoney", "PageUrl", "ReturnUrl", "NoticeType"); foreach ($signarray as $v) { $md5str .= $data[$v] . '|'; } $md5str .= $this->payConfig['baofoo']['pkey']; $md5str = md5($md5str); return $md5str; break; case "baofoo_return": $signarray = array("MemberID", "TerminalID", "TransID", "Result", "ResultDesc", "FactMoney", "AdditionalInfo", 'SuccTime'); foreach ($signarray as $v) { $md5str .= "{$v}" . '=' . $data[$v] . '~|~'; } //dump($md5str); $md5str .= 'Md5Sign=' . $this->payConfig['baofoo']['pkey']; $md5str = md5($md5str); return $md5str; break; case "shengpay": $signarray = array('Name', 'Version', 'Charset', 'MsgSender', 'SendTime', 'OrderNo', 'OrderAmount', 'OrderTime', 'PayType', 'PageUrl', 'NotifyUrl', 'ProductName', 'BuyerContact', 'BuyerIp', 'Ext1', 'Ext2', 'SignType'); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['shengpay']['pkey']; //MD5密钥 $md5str = strtoupper(md5($md5str)); return $md5str; break; case "shengpay_return": $signarray = array('Name', 'Version', 'Charset', 'TraceNo', 'MsgSender', 'SendTime', 'InstCode', 'OrderNo', 'OrderAmount', 'TransNo', 'TransAmount', 'TransStatus', 'TransType', 'TransTime', 'MerchantNo', 'ErrorCode', 'ErrorMsg', 'Ext1', 'Ext2', 'SignType'); foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= "{$data[$v]}"; } } $md5str .= $this->payConfig['shengpay']['mkey']; $md5str = strtoupper(md5($md5str)); return $md5str; break; case "tenpay": $signPars = ""; ksort($data); foreach ($data as $k => $v) { if ("" != $v && "sign" != $k) { $signPars .= $k . "=" . $v . "&"; } } $signPars .= "key=" . $this->payConfig['tenpay']['key']; $md5str = strtoupper(md5($signPars)); return $md5str; break; case "ecpss": $signarray = array('MerNo', 'BillNo', 'Amount', 'ReturnURL'); //校验源字符串 foreach ($signarray as $v) { if (!isset($data[$v])) { $md5str .= ""; } else { $md5str .= $data[$v]; } } $md5str .= $this->payConfig['ecpss']['MD5key']; //MD5密钥 $md5str = strtoupper(md5($md5str)); return $md5str; break; case "ecpss_return": $signarray = array("BillNo", "Amount", "Succeed"); //校验源字符串 foreach ($signarray as $v) { $md5str .= $data[$v] . "&"; } $md5str .= $this->payConfig['ecpss']['MD5key']; $md5str = strtoupper(md5($md5str)); return $md5str; break; case "easypay": //易生支付 $para = array(); while (list($key, $val) = each($data)) { if ($key == "sign" || $key == "sign_type" || $val == "") { continue; } else { $para[$key] = $data[$key]; } } ksort($para); reset($para); $signPars = ""; while (list($key, $val) = each($para)) { $signPars .= $key . "=" . $val . "&"; } $signPars = substr($signPars, 0, count($signPars) - 2); //去掉最后一个&字符 $signPars .= $this->payConfig['easypay']['key']; $md5str = md5($signPars); return $md5str; break; case "cmpay": //中国移动 $signarray = array('merchantId', 'payNo', 'returnCode', 'message', 'signType', 'type', 'version', 'amount', 'amtItem', 'bankAbbr', 'mobile', 'orderId', 'payDate', 'accountDate', 'reserved1', 'reserved2', 'status', 'orderDate', 'fee'); foreach ($signarray as $v) { $mac .= $data[$v]; } $signKey = $this->payConfig['cmpay']['serverCert']; $mac = MD5sign($signKey, $mac); return $mac; break; case "cmpay_return": //中国移动 foreach ($data as $v) { $mac .= $v; } $signKey = $this->payConfig['cmpay']['serverCert']; //MD5方式签名 $hmac = MD5sign($signKey, $mac); return $hmac; break; case "allinpay": $signarray = array("inputCharset", "pickupUrl", "receiveUrl", "version", "language", "signType", "merchantId", "payerName", "payerEmail", "payerTelephone", "payerIDCard", "pid", "orderNo", "orderAmount", "orderCurrency", "orderDatetime", "orderExpireDatetime", "productName", "productPrice", "productNum", "productId", "productDescription", "ext1", "ext2", "payType", "issuerId", "pan"); $i = 0; foreach ($signarray as $v) { if (0 < $i) { if ($data[$v] !== "") { $md5str .= "&{$v}=" . $data[$v]; } } else { if ($data[$v] !== "") { $md5str .= "{$v}=" . $data[$v]; } } ++$i; } $md5str .= "&key=" . $this->payConfig['allinpay']['key']; $md5str = strtoupper(md5($md5str)); return $md5str; case "allinpay_return": $signarray = array("merchantId", "version", "language", "signType", "payType", "issuerId", "paymentOrderId", "orderNo", "orderDatetime", "orderAmount", "payDatetime", "payAmount", "ext1", "ext2", "payResult", "errorCode", "returnDatetime"); $i = 0; foreach ($signarray as $v) { if (0 < $i) { if ($data[$v] !== "") { $md5str .= "&{$v}=" . $data[$v]; } } else { if ($data[$v] !== "") { $md5str .= "{$v}=" . $data[$v]; } } ++$i; } //解析publickey.txt文本获取公钥信息 require_once C("APP_ROOT") . "Lib/Pay/allinpay/php_rsa.php"; $publickeyfile = C("APP_ROOT") . "Lib/Pay/allinpay/publickey.txt"; $publickeycontent = file_get_contents($publickeyfile); //echo "<br>".$content; $publickeyarray = explode(PHP_EOL, $publickeycontent); $publickey = explode('=', $publickeyarray[0]); $modulus = explode('=', $publickeyarray[1]); $keylength = 1024; $verify_result = rsa_verify($md5str, $data['signMsg'], $publickey[1], $modulus[1], $keylength, "sha1"); return $verify_result; } }