MD5Util方法
パッケージcom.funcanteen.business.action.pay.util。 輸入java.security.MessageDigestの; パブリッククラスMD5Util { プライベート静的な文字列byteArrayToHexString(バイトB []){ StringBufferのresultSb =新規のStringBuffer(); 以下のために(INT i = 0; iがてb.lengthを<; iは++) resultSb.append(byteToHexString(B [I]))。 )(resultSb.toStringを返します。 } プライベート静的な文字列byteToHexString(バイトB){ int型N = B。 IF(N <0) 、N + = 256。 INT D1 = N / 16。 D2 INT = N%16。 hexDigits [D1] + hexDigits [D2]を返します。 } 公共の静的な文字列MD5Encode(文字列原点、ストリングたcharsetName){ 文字列resultString = NULL; 試す{ resultString =新しい文字列(原点); するMessageDigest MD = MessageDigest.getInstance( "MD5")。 IF(たcharsetName == NULL || "" .equals(たcharsetName)) resultString = byteArrayToHexString(md.digest(resultString .getBytes()))。 他 resultString = byteArrayToHexString(md.digest(resultString .getBytes(たcharsetName))); }キャッチ(例外例外){ } resultStringを返します。 } プライベート静的最終的な文字列hexDigits [] = { "0"、 "1"、 "2"、 "3"、 "4"、 "5"、 "6"、 "7"、 "8"、 "9"、 " A」、 "B"、 "C"、 "D"、 "E"、 "F"}。 }
2:署名包装方法
//设置签名 パブリックストリングgetSignature(MAP <文字列、文字列>マップ){ StringBufferのSB =新規のStringBuffer(); (map.entrySet()のMap.Entry <文字列、文字列> ME){ため 。( "=")追加sb.append(me.getKey())(me.getValue())を追加追加( "&。 「); } sb.append( "キー=")付加( "xxxxxxxxxxxxxxxxxxxx")。 MD5Util.MD5Encode(sb.toString()、nullを)返します。 }
3:署名メソッドを呼び出します
//要发送给用户的模板信息 のTreeMap <文字列、文字列> josnMap =新規のTreeMap <文字列、文字列>(); josnMap.put( "名前"、stallApply.getAccountName()); ストリングjsonData = JSON.toJSONString(josnMap)。 //封装组装签名 地図<文字列、文字列>マップ=新しいTreeMapを<文字列、文字列>(); 文字列タイムスタンプ=のSystem.currentTimeMillis()/ 1000+ ""; map.put( "JSON"、jsonData)。 map.put( "モバイル"、stallApply.getMobile()); map.put( "templateCode"、 "SMS_74665033"); map.put( "タイムスタンプ"、タイムスタンプ)。
MD5Util方法
パッケージcom.funcanteen.business.action.pay.util。 輸入java.security.MessageDigestの; パブリッククラスMD5Util { プライベート静的な文字列byteArrayToHexString(バイトB []){ StringBufferのresultSb =新規のStringBuffer(); 以下のために(INT i = 0; iがてb.lengthを<; iは++) resultSb.append(byteToHexString(B [I]))。 )(resultSb.toStringを返します。 } プライベート静的な文字列byteToHexString(バイトB){ int型N = B。 IF(N <0) 、N + = 256。 INT D1 = N / 16。 D2 INT = N%16。 hexDigits [D1] + hexDigits [D2]を返します。 } 公共の静的な文字列MD5Encode(文字列原点、ストリングたcharsetName){ 文字列resultString = NULL; 試す{ resultString =新しい文字列(原点); するMessageDigest MD = MessageDigest.getInstance( "MD5")。 IF(たcharsetName == NULL || "" .equals(たcharsetName)) resultString = byteArrayToHexString(md.digest(resultString .getBytes()))。 他 resultString = byteArrayToHexString(md.digest(resultString .getBytes(たcharsetName))); }キャッチ(例外例外){ } resultStringを返します。 } プライベート静的最終的な文字列hexDigits [] = { "0"、 "1"、 "2"、 "3"、 "4"、 "5"、 "6"、 "7"、 "8"、 "9"、 " A」、 "B"、 "C"、 "D"、 "E"、 "F"}。 }
2:署名包装方法
//设置签名 パブリックストリングgetSignature(MAP <文字列、文字列>マップ){ StringBufferのSB =新規のStringBuffer(); (map.entrySet()のMap.Entry <文字列、文字列> ME){ため 。( "=")追加sb.append(me.getKey())(me.getValue())を追加追加( "&。 「); } sb.append( "キー=")付加( "xxxxxxxxxxxxxxxxxxxx")。 MD5Util.MD5Encode(sb.toString()、nullを)返します。 }
3:署名メソッドを呼び出します
//要发送给用户的模板信息 のTreeMap <文字列、文字列> josnMap =新規のTreeMap <文字列、文字列>(); josnMap.put( "名前"、stallApply.getAccountName()); ストリングjsonData = JSON.toJSONString(josnMap)。 //封装组装签名 地図<文字列、文字列>マップ=新しいTreeMapを<文字列、文字列>(); 文字列タイムスタンプ=のSystem.currentTimeMillis()/ 1000+ ""; map.put( "JSON"、jsonData)。 map.put( "モバイル"、stallApply.getMobile()); map.put( "templateCode"、 "SMS_74665033"); map.put( "タイムスタンプ"、タイムスタンプ)。