您好,登錄后才能下訂單哦!
<?php //私鑰和公鑰在芝麻信用后臺設置,官網有詳細說明 class ZhimaAction extends CommonAction { //芝麻信用網關地址 public $gatewayUrl = "https://zmopenapi.zmxy.com.cn/openapi.do"; //商戶私鑰文件 public $privateKeyFile = "商戶私鑰文件(絕對路徑)"; //芝麻公鑰文件 public $zmPublicKeyFile = "芝麻公鑰文件(絕對路徑)"; //數據編碼格式 public $charset = "UTF-8"; //應用id public $app_id = "*******"; //要調用的接口名 public $method = "zhima.credit.score.get"; //來源平臺,默認為zmop public $platform = "zmop"; //接口版本,目前只支持1.0 public $version = "1.0"; // 加密后信息 RSA加密后的業務參數 public $params = ""; // 加密后信息 對params參數加密前的簽名,算法為SHA1WithRSA public $sign = "1.0"; /* 加簽過程 1、在加密過程的第一步,我們得到了拼接在一起的業務參數,同樣以芝麻信用評分為例,拼接的參數如下: transaction_id=URLEncode(1234567)&product_code=URLEncode(w1010100100000000001)&open_id=URLEncode(268810000007909449496) 2、使用 SHA1WithRSA 算法以及商戶自己的私鑰進行簽名,得到 byte 數組 SHA1WithRSA(transaction_id=URLEncode(1234567)&product_code=URLEncode(w1010100100000000001)&open_id=URLEncode(268810000007909449496)) 3、將 byte 數組進行 Base64 編碼,得到一個簽名的字符串 Base64(SHA1WithRSA(transaction_id=URLEncode(1234567)&product_code=URLEncode(w1010100100000000001)&open_id=URLEncode(268810000007909449496))) 經過了上述三步,我們便得到了業務參數的簽名,最后我們將這個簽名的值放入系統參數 sign 中: sign=Base64(SHA1WithRSA(transaction_id=URLEncode(1234567)&product_code=URLEncode(w1010100100000000001)&open_id=URLEncode(268810000007909449496))) 解密和驗簽 */ public function __construct() { parent::__construct(); //在官網下載 Vendor('zhima.zmop.ZmopClient'); Vendor('zhima.zmop.RSAUtil'); Vendor('zhima.zmop.ZhimaCreditIvsDetailGetRequest'); Vendor('zhima.ZmopSdk'); } public function grant(){ if(IS_POST){ $name = I('name');//姓名 $IDnumber = I('IDnumber'); //×××號碼 $client = new ZmopClient($this->gatewayUrl,$this->app_id,$this->charset,$this->privateKeyFile,$this->zmPublicKeyFile); $RSAUtil = new RSAUtil(); $identity_type ='2'; $identity_param =json_encode(array('certNo'=>$IDnumber,'name'=>$name,'certType'=>"IDENTITY_CARD")); $request['app_id'] = $this->app_id; $request['charset'] = $this->charset; $request['method'] = 'zhima.auth.info.authorize'; $request['version'] = $this->version; $request['platform'] = $this->platform; $request['params'] = $RSAUtil->rsaEncrypt($str,$this->zmPublicKeyFile); $request['sign'] = $RSAUtil->sign($str,$this->privateKeyFile); $request['identity_type'] = $identity_type; $request['identity_param'] = $identity_param; $str ='identity_type='.urlencode($identity_type).'&identity_param='.urlencode($identity_param).''; $request = new ZhimaAuthInfoAuthorizeRequest (); $request->setIdentityType ("2"); // $request->setParams ("2"); $request->setIdentityParam ($identity_param); //$request->setBizParams ( "{\"auth_code\":\"M_APPPC_CERT\",\"state\":\"透傳參數\"}" ); // $url = $client->generatePageRedirectInvokeUrl ( $request ); //dump($url); if($url){ $json['msg'] =1; $json['url'] =$url; }else{ $json['msg'] =0; $json['info'] ='參數錯誤'; } echo json_encode($json);exit; }else{ $json['msg'] =0; $json['info'] ='參數錯誤'; echo json_encode($json);exit; } } //返回 public function returndata(){ $params=$_GET['params']; $sign=$_GET['sign']; if(!$sign){ $this->redirect('Member/rz');exit; } // 判斷串中是否有%,有則需要decode // dump($sign); $params = strstr ( $params, '%' ) ? urldecode ( $params ) : $params; $sign = strstr ( $sign, '%' ) ? urldecode ( $sign ) : $sign; $client = new ZmopClient ( $this->gatewayUrl, $this->app_id, $this->charset, $this->privateKeyFile, $this->zmPublicKeyFile ); $result = $client->decryptAndVerifySign ( $params, $sign ); //轉數組 $parts = explode('&',$result); $array=array(); foreach($parts as $k=>$v){ $parts[$k] = explode('=',$v); $array[$parts[$k]['0']] = $parts[$k]['1']; } //dump($array['success']='false'); if($array['success']!='false'){ //dump($array);exit; $res =$this->ToRz($array); if($res->success){ //返回數據 更新會員信息 $is_zhima = M('member')->where(array('id'=>cookie('id')))->find(); if($is_zhima['zhima']!=$res->zm_score){ $save['open_id'] = $array['open_id']; $save['zhima'] = $res->zm_score; $save['state'] = '1'; $save['optime'] = time(); $save['rztime'] = time(); $member = M('member')->where(array('id'=>cookie('id')))->save($save); } echo '<script>alert("認證成功");window.location.href ="/Member/rz"</script>'; } ///dump($member); // dump($result); }else{ //echo '<script>alert("驗簽失敗");window.location.href ="/Member/rz"</script>'; $this->redirect('Member/rz');exit; } } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。