sha1 from Java to Php

将一个sha1加密算法从Java改写到PHP

	// 身份证简项认证
	public static void idenAuth() {

		String appId = APP_ID;
		String serviceCode = "idc0001";
		String name = "南建坤";
		String idCard= "130521198709140030";
		String selfUrl= null;
		String selfImg= null;
		String bankcard=null;
		String mobile=null;

		Map<String, Object> param = new HashMap<String, Object>();
		param.put("appId",  appId);
		param.put("serviceCode", serviceCode);
		param.put("name", name);
		param.put("idCard", idCard);
		try {
			Map<String, String> headers = new HashMap<String, String>();
			headers.put("Content-Signature", "HMAC-SHA1 " + new Base64().encodeToString(HMACSHA1.getHmacSHA1(appId+serviceCode+name+idCard+
					selfUrl+selfImg+bankcard+mobile, SECRET_KEY)));

			String resStr = new HttpClientService().postForm(URL, headers, param);
			System.out.println(resStr);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
function tianweiApiIdcard($path,$body_arr) {
	$url = "http://demo-open.itruscloud.com/apigate/authapi";
	$APP_ID = "app_id";
	$SECRET_KEY = "key";
    $bodys=http_build_query(array_merge(['appId'=>$APP_ID],$body_arr));
	$signature_data = $APP_ID.$body_arr['serviceCode'].$body_arr['name'].$body_arr['idCard'].$body_arr['selfUrl'].$body_arr['selfImg'].$body_arr['bankcard'].$body_arr['mobile'];
    $headers = array();
    array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded");
    array_push($headers, "Content-Signature".":"."HMAC-SHA1 ".base64_encode(hash_hmac('sha1',$signature_data, $SECRET_KEY,true)));
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($curl, CURLOPT_URL, $url.$path);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    if (!empty($bodys)) {
        curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
    }
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}
$response = tianweiApiIdcard('/person/authIden',[
    'serviceCode'=>'idc0001',
    'name'=>'韩国',
    'idCard'=>'429006197109275750',
    'selfUrl'=>'null',
    'selfImg'=>'null',
    'bankcard'=>'null',
    'mobile'=>'null',
]);

$result = json_decode(json_decode($response),true);
// if(isset($result['status']) && "1" ==$result['status']) {
//     echo '成功!';
// }
var_dump($result);