| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace common\pay\globalpay;
- class PayUtils
- {
- /**
- * @param array $data
- * @return string
- */
- public static function makeSign($data, $privateKey)
- {
- $temp_str = "";
- $temp_str = $data["mchNo"].$data["customerNo"].$data["orderNo"].$data["amount"].$data["currency"].$data["returnUrl"].$data["notifyUrl"].$data["payType"].$privateKey;
- $sign = MD5($temp_str);
- return $sign;
- }
- /**
- * @param array $data
- * @param $pubCert
- * @return bool|int
- */
- public static function verify($data, $privateKey)
- {
- // 签名
- if (!isset($data['sign']) || trim($data['sign']) === '') {
- return false;
- }
- $sign = $data['sign'];
- $temp_str = $data["mchNo"].$data["customerNo"].$data["orderNo"].$data["amount"].$data["currency"].$data["orderId"].$data["transactionId"].$privateKey;
- $new_sign=MD5($temp_str);
- if($new_sign == $sign ){
- return true;
- }else{
- return false;
- }
-
- }
- // 请求函数
- public static function send($data, $payUrl){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,$payUrl);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json"));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $server_output = curl_exec($ch);
- $resp = json_decode($server_output, true);
- return $resp;
- }
- }
|