Subversion Repositories php-qbpwcf

Rev

Rev 323 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 323 Rev 324
Line 1031... Line 1031...
1031
		}#if end
1031
		}#if end
1032
		
1032
		
1033
	#取得加密後的msg
1033
	#取得加密後的msg
1034
	$msg=$enCodeStr["content"];
1034
	$msg=$enCodeStr["content"];
1035
 
1035
 
-
 
1036
	#產生亂數
-
 
1037
	#函式說明:
-
 
1038
	#建立以圖片(PNG格式)呈現的驗證碼.
-
 
1039
	#回傳的解果:
-
 
1040
	#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
-
 
1041
	#$result["error"],錯誤訊息.
-
 
1042
	#$result["function"],檔前執行的函數名稱.
-
 
1043
	#$result["randNumberWord"],傳驗證碼的內容.
-
 
1044
	#$result["imgAddress"],包含src圖片的位置與名稱.
-
 
1045
	#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
-
 
1046
	#必填參數:
-
 
1047
	#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
-
 
1048
	$conf["imgAddressAndName"]="/tmp/notExsit.img";
-
 
1049
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
1050
	$conf["fileArgu"]=__FILE__;
-
 
1051
	#可省略參數:
-
 
1052
	#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
-
 
1053
	#$conf["num"]="8";
-
 
1054
	#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
-
 
1055
	$conf["disableImg"]="true";
-
 
1056
	#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
-
 
1057
	#$conf["imgToData"]="true";
-
 
1058
	#$conf["class"],字串,圖片要套用的css樣式類別.
-
 
1059
	#$conf["class"]="";
-
 
1060
	#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
-
 
1061
	#$conf["content"]=array();
-
 
1062
	#參考資料:
-
 
1063
	#無.
-
 
1064
	#備註:
-
 
1065
	#無.
-
 
1066
	$validationCode=authenticate::validationCode($conf);
-
 
1067
	unset($conf);
-
 
1068
 
-
 
1069
	#如果執行失敗
-
 
1070
	if($validationCode["status"]==="false"){
-
 
1071
 
-
 
1072
		#函式說明:
-
 
1073
		#撰寫log
-
 
1074
		#回傳結果:
-
 
1075
		#$result["status"],狀態,"true"或"false".
-
 
1076
		#$result["error"],錯誤訊息陣列.
-
 
1077
		#$result["function"],當前函式的名稱.
-
 
1078
		#$result["argu"],使用的參數.
-
 
1079
		#必填參數:
-
 
1080
		#$conf["path"],字串,log檔案的路徑與名稱.
-
 
1081
		$conf["path"]=$logFile;
-
 
1082
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
1083
		$conf["content"]=$validationCode;
-
 
1084
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
1085
		$conf["fileArgu"]=__FILE__;
-
 
1086
		#可省略參數:
-
 
1087
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
1088
		#$conf["rewrite"]="false";
-
 
1089
		#參考資料:
-
 
1090
		#無.
-
 
1091
		#備註:
-
 
1092
		#無.
-
 
1093
		$record=logs::record($conf);
-
 
1094
		unset($conf);
-
 
1095
 
-
 
1096
		#如果寫log失敗
-
 
1097
		if($record["status"]==="false"){
-
 
1098
 
-
 
1099
			#印出json結果
-
 
1100
			echo json_encode($record);
-
 
1101
 
-
 
1102
			}#if end
-
 
1103
 
-
 
1104
		#結束執行,回傳錯誤代碼1
-
 
1105
		exit(1);
-
 
1106
 
-
 
1107
		}#if end
-
 
1108
 
-
 
1109
	#隨機產生get變數名稱
-
 
1110
	$getVarName=$validationCode["randNumberWord"];
-
 
1111
 
-
 
1112
	#儲存含有亂數get名稱的from數值
-
 
1113
	$from=$getVarName."=server";
-
 
1114
	
-
 
1115
	#加密要傳遞的訊息內容
-
 
1116
	#函式說明:
-
 
1117
	#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
1118
	#回傳結果:
-
 
1119
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
1120
	#$result["function"],當前執行的函數名稱.
-
 
1121
	#$result["content"],加密後的結果.
-
 
1122
	#$result["error"],錯誤訊息陣列.
-
 
1123
	#$result["argu"],使用的參數.
-
 
1124
	#必填參數:
-
 
1125
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
1126
	$conf["enCodeStr"]=$from;
-
 
1127
	#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg",8種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過先json_encdoe後再urlencode最後再base64_encode後bin2hex的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key.
-
 
1128
	$conf["enCodeType"]="gpg";
-
 
1129
	#可省略參數:
-
 
1130
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
1131
	#$conf["sha1Raw"]="false";
-
 
1132
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
1133
	#$conf["p_hash"]="";
-
 
1134
	#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
1135
	#$conf["keyForAes256"]="";
-
 
1136
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
1137
	#$conf["aes256Encode"]="";
-
 
1138
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
1139
	#$conf["qbpwcfDecode"]="false";
-
 
1140
	#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
1141
	#$conf["gpgDecrypt"]="true";
-
 
1142
	#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
1143
	#$conf["gpgId"]="";
-
 
1144
	#參考資料:
-
 
1145
	#sha1=>http://php.net/manual/en/function.sha1.php
-
 
1146
	#md5=>http://php.net/manual/en/function.md5.php
-
 
1147
	#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
1148
	#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
1149
	#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
1150
	#備註:
-
 
1151
	#無.
-
 
1152
	$enCodeStr=authenticate::enCodeStr($conf);
-
 
1153
	unset($conf);
-
 
1154
 
-
 
1155
	#如果執行失敗
-
 
1156
	if($enCodeStr["status"]==="false"){
-
 
1157
 
-
 
1158
		#函式說明:
-
 
1159
		#撰寫log
-
 
1160
		#回傳結果:
-
 
1161
		#$result["status"],狀態,"true"或"false".
-
 
1162
		#$result["error"],錯誤訊息陣列.
-
 
1163
		#$result["function"],當前函式的名稱.
-
 
1164
		#$result["argu"],使用的參數.
-
 
1165
		#必填參數:
-
 
1166
		#$conf["path"],字串,log檔案的路徑與名稱.
-
 
1167
		$conf["path"]=$logFile;
-
 
1168
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
1169
		$conf["content"]=$enCodeStr;
-
 
1170
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
1171
		$conf["fileArgu"]=__FILE__;
-
 
1172
		#可省略參數:
-
 
1173
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
1174
		#$conf["rewrite"]="false";
-
 
1175
		#參考資料:
-
 
1176
		#無.
-
 
1177
		#備註:
-
 
1178
		#無.
-
 
1179
		$record=logs::record($conf);
-
 
1180
		unset($conf);
-
 
1181
 
-
 
1182
		#如果寫log失敗
-
 
1183
		if($record["status"]==="false"){
-
 
1184
 
-
 
1185
			#印出json結果
-
 
1186
			echo json_encode($record);
-
 
1187
 
-
 
1188
			}#if end
-
 
1189
 
-
 
1190
		#結束執行,回傳錯誤代碼1
-
 
1191
		exit(1);
-
 
1192
 
-
 
1193
		}#if end
-
 
1194
		
-
 
1195
	#取得加密後的from
-
 
1196
	$from=$enCodeStr["content"];
-
 
1197
 
1036
	#初始化要傳遞的json字串
1198
	#初始化要傳遞的json字串
1037
	$json=array();
1199
	$json=array();
1038
	
1200
	
-
 
1201
	#設置傳送訊息的來源
-
 
1202
	$json["from"]=base64_encode($from);
-
 
1203
	
1039
	#設置接收訊息的id(加密過)
1204
	#設置接收訊息的id(加密過)
1040
	$json["to"]=base64_encode($wsRevId);
1205
	$json["to"]=base64_encode($wsRevId);
1041
	
1206
	
1042
	#設置要傳遞加密後訊息的內容
1207
	#設置要傳遞加密後訊息的內容
1043
	$json["content"]=base64_encode($msg);
1208
	$json["content"]=base64_encode($msg);