查看文件: b2c.php
大小: 4.81 KB
类型: application/octet-stream
<?php //第一种方法 //这样php就接收到postman发送过来的json值了 // $response = json_decode(file_get_contents('php://input"'), true); //第二种方法 //这样php就接妆到postman发送过来的json值了 $response = $GLOBALS[ 'HTTP_RAW_POST_DATA']; $logpath="/www/yuxingo/billtest/log.txt"; $fp = fopen($logpath, "a"); $ref=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:""; $myip= $_SERVER['REMOTE_ADDR']; fwrite($fp,"== start log ===".$myip.",".date('Y-m-d H:i:s')." \r\n"); //fwrite($fp,"start log ".$ref." response " .date('Y-m-d H:i:s')."\r\n"); $response = $GLOBALS[ 'HTTP_RAW_POST_DATA']; $array = json_decode($response, true); //fwrite($fp,"================== order decode================================="."\r\n"); //fwrite($fp,"orderCode:".$array['orderCode']."\r\n");// 822344324 //fwrite($fp,"idno :".$array['idno']."\r\n");// 822344324 fwrite($fp,"================== String upload string ==================================="."\r\n"); fwrite($fp, $response."\r\n");// 822344324 fwrite($fp,"================== end upload string==================================="."\r\n"); //$data ='{"msg":"林文隆無效無效無效","success":"true","code":"0222212591892"}'; //$data ='{"msg":"OK","success":"true","code":"5678909892"}'; // $data ='{"msg":"OK","success":"true","code":"56789012","sg":[{"nc":12},{"nc":14}]}'; // $data ='{"msg":"OK","success":"true","code":"56789012"}'; /** whatever you're serializing **/; // header('Content-Type: application/json; charset=utf-8'); // header('Content-Type: text/json; charset=utf-8'); // echo "\r\n"; // $json=json_encode($response);//$data //$decoded_json = $decoded_json['timeStamp'];//->timeStamp json_decode($json, false); $decoded_json = json_decode($response, true); // $decoded_json->timeStamp; fwrite($fp,"================== timeStamp ==================================="."\r\n"); fwrite($fp, $decoded_json['timeStamp'] ."\r\n");// 822344324 // timeStamp+idno+password(登錄密碼),MD5 轉大寫獲取的參 /* uncode idno pwd 鈺興 29368552 G222199818 開興 37843931 G222203746 鈺立 90601546 G122371916 0934027488 */ if($decoded_json['uncode']=='29368552'){ $decoded_json['idno']='G222199818'; $pwd='0912091011'; } else if($decoded_json['uncode']=='37843931'){ $decoded_json['idno']='G222203746'; $pwd='0953532556'; } else if($decoded_json['uncode']=='90601546'){ $decoded_json['idno']='G122371916'; $pwd='0934027488'; }else if($decoded_json['uncode']=='87379727'){ $decoded_json['idno']='G121272281'; $pwd='2xjuUdru'; } // $decoded_json['idno']='G121272281'; // $decoded_json['timeStamp']=time().'000'; $sign= $decoded_json['timeStamp'].$decoded_json['idno'].$pwd ;// 822344324 // java 參考:Md5.MD5(timeStamp+idno+password).toUpperCase(),詳細參考 demo $sign= strtoupper(md5($sign)); $decoded_json['sign']=$sign; fwrite($fp,"====sign==".$sign."\r\n"); $jss=json_encode($decoded_json); fwrite($fp, $jss."\r\n"); fwrite($fp,"================== end timeStamp ==================================="."\r\n"); //rta := IdHTTP1.Post('https://www.giveme.com.tw/invoice.do?action=addB2C', JsonToSend);//PostData $url='https://www.giveme.com.tw/invoice.do?action=addB2C'; if(strlen($decoded_json['phone'])==8 ){ if(substr($decoded_json['phone'],0,1)<>'/') { $url='https://www.giveme.com.tw/invoice.do?action=addB2B'; fwrite($fp,"====addB2B==\r\n"); } } // disable post $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: OAuth 2.0 token here")); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jss); $result = curl_exec($ch); fwrite($fp,"================== result ==================================="."\r\n"); fwrite($fp,$result."\r\n"); $test_dejson = json_decode($result, true); // echo 'billcode,'.$result_dejson['code'] ;//"code":"VJ59556740", fclose($fp); // $testjs='{"msg":"開立成功!","code":"VJ59556740","totalFee":"10元","phone":"","success":"true","orderCode":"/8S1677q"}'; //$testjs='{"msg":"無效無效無效","success":"false"}'; // $test_dejson = json_decode($testjs, true); echo "\r\n"; if(isset($test_dejson['msg']) && $test_dejson['msg']=="開立成功!"){ echo 'ret,billcode,'.$test_dejson['code'] ;//"code":"VJ59556740", } else{ $msg='err'; if(isset($test_dejson['msg'])){ $msg=mb_convert_encoding($test_dejson['msg'],"big5","utf-8"); } echo 'ret,err,'.$msg ; } ?>
保存
取消
返回文件列表