<?php
header('Content-Type: application/json; charset=utf-8');
include("../function/func.php");
$data = json_decode(file_get_contents('php://input'), true);
$orderID=$data['orderID'];
$type=(String)$data['type'];
$picName=$data['picName'];
$base64Image=$data['pic'];
$fileType=end(explode( '.', $picName));
$newPicName=rand(0,10000)."sign".date("YmdHis").".".$fileType;
$data = explode( ',', $base64Image);
$filePath=base64_to_jpeg($base64Image,"../signPics/".$newPicName);

$resultCode['retCode']=1;
$resultCode['resMessage']="";

if($type==""){
    $resultCode['retCode']=0;
    $resultCode['resMessage']="請完整填入類型";
}elseif($picName==""){
    $resultCode['retCode']=0;
    $resultCode['resMessage']="請完整填入檔名";
}elseif($base64Image==""){
    $resultCode['retCode']=0;
    $resultCode['resMessage']="請完整填入base64檔案內容";
}else{
    //取得實際id
    $id=getIDFromOrderID($orderID);
    $result=createSignData($id,$type,$newPicName);
    if($result!=1){
        $resultCode['retCode']=0;
        $resultCode['resMessage']=$result;
        $resultCode['filePath']=$filePath;
    }
}

echo json_encode($resultCode);
?>