| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace common\pay\shanfutong;
- class PayUtils
- {
- /**
- * @param array $data
- * @return string
- */
- public static function makeSign($data, $key)
- {
- $merchantid = $data['uid'];
- $price = sprintf("%.2f",$data['price']);
- $paytype = $data['paytype'];
- $notify_url = $data['notify_url'];
- $return_url = $data['return_url'];
- $user_order_no = $data['user_order_no'];
- $sign = md5("{$merchantid}"."{$price}"."{$paytype}"."{$notify_url}"."{$return_url}"."{$user_order_no}"."{$key}");
- return strtolower($sign);
- }
- /**
- * @param array $data
- * @param $key
- * @return bool|int
- */
- public static function verify($data, $key)
- {
- // 签名
- if (!isset($data['sign']) || trim($data['sign']) === '') {
- return false;
- }
- $user_order_no = $data['user_order_no']; //订单号码(商户传递过去的)
- $orderno = $data['orderno']; //平台生成的订单
- $tradeno = $data['tradeno']; //支付的流水号
- $price = sprintf("%.2f",$data['price']); //订单金额 (这里保留两位小数)
- $realprice = sprintf("%.2f",$data['realprice']); //真实的金额 (这里保留两位小数)
- $tokenkey = $key; //token
- $sign = $data['sign'];
-
- $sing_new = md5("{$user_order_no}"."{$orderno}"."{$tradeno}"."{$price}"."{$realprice}"."{$tokenkey}"); //自己加密的密钥
- $sing_new = strtolower($sing_new); //转化为小写
- // 比较两次的签名是否一致
- if($sign == $sing_new){
- return true;
- }else{
- return false;
- }
-
- }
- }
|