import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.util.SortedMap;
import java.util.TreeMap;

class Main {

	public static void main(String[] args) {
        SortedMap<String, String> map = new TreeMap<String, String>();
        map.put("mac","12:60:ec:f6:79:d7");
        map.put("errorTime","2018-12-28 10:14:20");
        map.put("errorCode","E001");
        map.put("errorDetail","{\"data\":\"http://images.81dd.cn/ef06592bdaef44ffaffeb0687e07269c\",\"type\":\"imgbox\"}");
		System.out.println(generateSign("5c6b880c62724c8e9a201e7adb0fb8bd",map));
	}

    public static boolean isValidStr(String str) {
        return str != null && str.trim().length() > 0 && !str.trim().equalsIgnoreCase("null");
    }

    public static String convertStrIfNull(Object str) {
        return str == null ? "" : str.toString();
    }

    /**
     * 签名算法
     * @param key  密钥
     * @param objcet 需要生成的签名参数
     * @return 签名字符串
     */
    public static String generateSign(String key, SortedMap<String, String> map) {
        try {
            String strToSign = getSignStr(map);
            if(isValidStr(key)){
                strToSign += "&" + key;
            }
            // 创建加密对象
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            // 传入要加密的字符串,按指定的字符集将字符串转换为字节流
            messageDigest.update(strToSign.getBytes("UTF-8"));
            byte byteBuffer[] = messageDigest.digest();
            // 將 byte数组转换为16进制string
            String sign = HexString(byteBuffer);
            return sign;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 获取加密字符串
     * @param objcet 需要加密的对象
     * @return 拼接完成需要加密的字符串
     */
    private static String getSignStr(SortedMap<String, String> map) {
        String strToSign = "";
        for (String attribute : map.keySet()) {
            strToSign += "&" + attribute + "=" + map.get(attribute);
        }
        strToSign = strToSign.substring(1, strToSign.length());
        return strToSign;
    }

    /**
     * 根据属性名获取属性值
     *
     * @param fieldName 属性名
     * @param o         需要获取的对象
     * @return
     */
    private static Object getFieldValueByName(String fieldName, Object o) {
        try {
            String firstLetter = fieldName.substring(0, 1).toUpperCase();
            String getter = "get" + firstLetter + fieldName.substring(1);
            Method method = o.getClass().getMethod(getter, new Class[]{});
            Object value = method.invoke(o, new Object[]{});
            return value;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 將 byte数组转换为16进制string
     *
     * @param baSrc 需要转换的数组
     * @return
     */
    public static String HexString(byte[] baSrc) {
        if (baSrc == null) {
            return "";
        }
        int nByteNum = baSrc.length;
        StringBuilder sbResult = new StringBuilder(nByteNum * 2);

        for (int i = 0; i < nByteNum; i++) {
            char chHex;

            byte btHigh = (byte) ((baSrc[i] & 0xF0) >> 4);
            if (btHigh < 10) {
                chHex = (char) ('0' + btHigh);
            } else {
                chHex = (char) ('A' + (btHigh - 10));
            }
            sbResult.append(chHex);

            byte btLow = (byte) (baSrc[i] & 0x0F);
            if (btLow < 10) {
                chHex = (char) ('0' + btLow);
            } else {
                chHex = (char) ('A' + (btLow - 10));
            }
            sbResult.append(chHex);
        }

        return sbResult.toString();
    }
}
liuliangwu01(webllw) - 2019-07-12 0 人
SHA-256加密


      PH - Warehouse/Storage

      @plugindesc This plugin allows the creation of warehouses where you can store items in the game.

      @author PrimeHover

      @version 1.0.0

      @date 11/14/2015

      ---------------------------------------------------------------------------------------

      This work is licensed under the Creative Commons Attribution 4.0 International License.

      To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/

      ---------------------------------------------------------------------------------------

      @param ---Vocabulary---

      @desc Use the spaces below to personalize the vocabulary of the plugin

      @default

      @param Withdraw Text

      @desc Text shown in option "Withdraw"

      @default Withdraw

      @param Deposit Text

      @desc Text shown in option "Deposit"

      @default Deposit

      @param Available Space Text

      @desc Text shown in the information window

      @default Available Space:

      @help

      Plugin Commands:

      - PHWarehouse create <Title of the Warehouse:50>               # Creates a warehouse with 50 spaces if it does not exist

      - PHWarehouse show <Title of the Warehouse>                    # Shows a warehouse

      - PHWarehouse remove <Title of the Warehouse>                  # Removes a warehouse

      The first command creates and opens a warehouse with the given title.

      If it already exists, the command will be ignored.

      Substitute "50" for the maximum number of spaces that the warehouse will have.

      If you leave the number in blank, the default size will be 50.

      Sizes cannot be changed.

      The second command opens the warehouse in the screen.

      The third command deletes an existent warehouse.

      Any remaining item in that specific warehouse will be removed as well.

      ========================================

      Script Calls: Use the commands below as a script command in a variable or conditional statement.

      - PHWarehouse.getMaxCapacity("Title of the Warehouse");        # Gets the maximum capacity of a warehouse (returns a number)

      - PHWarehouse.getCurrentCapacity("Title of the Warehouse");    # Gets the current capacity of a warehouse (returns a number)

      - PHWarehouse.exist("Title of the Warehouse");                 # Checks if a warehouse exists (returns true or false)

      */

      /* Global variable for management of the warehouses */

      var PHWarehouse;

      (function() {

      /* Getting the parameters */

      var parameters = PluginManager.parameters('PH_Warehouse');

      var withdrawText = String(parameters['Withdraw Text']);

      var depositText = String(parameters['Deposit Text']);

      var availableSpaceText = String(parameters['Available Space Text']);

      /* ---------------------------------------------------------- *

      *                      WAREHOUSE MANAGER                     *

      * ---------------------------------------------------------- */

      function PHWarehouseManager() {

      this._warehouses = {};

      this._lastActive = "";

      this._lastOption = 0; // 0 = Withdraw, 1 = Deposit

      this._lastCategory = "item";

      }

      /* Creates a warehouse if it does not exist */

      PHWarehouseManager.prototype.createWarehouse = function(_sentence) {

      var matches = this.checkSentence(_sentence);

      var results;

      var title;

      var capacity = 50;

      if (matches != null) {

      results = matches[1].split(":");

      title = results[0];

      if (!this._warehouses.hasOwnProperty(title)) {

      if (results.length == 2) {

      capacity = parseInt(results[1]);

      if (isNaN(capacity) || capacity <= 0) {

      capacity = 50;

      }

      }

      this._warehouses[title] = {

      title: title,

      maxCapacity: capacity,

      currentCapacity: 0,

      items: {

      item: [],

      weapon: [],

      armor: [],

      keyItem: []

      },

      qtty: {

      item: {},

      weapon: {},

      armor: {},

      keyItem: {}

      }

      };

      }

      this._lastActive = title;

      }

      };

      /* Opens a warehouse */

      PHWarehouseManager.prototype.openWarehouse = function(_sentence) {

      var matches = this.checkSentence(_sentence);

      if (matches != null) {

      this._lastActive = matches[1];

      }

      };

      /* Get all the items from the current warehouse */

      PHWarehouseManager.prototype.getItems = function() {

      var totalItems = this.getCommonItems();

      totalItems = totalItems.concat(this.getArmors());

      totalItems = totalItems.concat(this.getKeyItems());

      totalItems = totalItems.concat(this.getWeapons());

      return totalItems;

      };

      /* Get weapon items */

      PHWarehouseManager.prototype.getWeapons = function() {

      var totalItems = [];

      for (var i = 0; i < this._warehouses[this._lastActive].items.weapon.length; i++) {

      for (var j = 0; j < $dataWeapons.length; j++) {

      if ($dataWeapons[j] != null && this._warehouses[this._lastActive].items.weapon[i] == $dataWeapons[j].id) {

      totalItems.push($dataWeapons[j]);

      }

      }

      }

      return totalItems;

      };

      /* Get common items */

      PHWarehouseManager.prototype.getCommonItems = function() {

      var totalItems = [];

      for (var i = 0; i < this._warehouses[this._lastActive].items.item.length; i++) {

      for (var j = 0; j < $dataItems.length; j++) {

      if ($dataItems[j] != null && this._warehouses[this._lastActive].items.item[i] == $dataItems[j].id) {

      totalItems.push($dataItems[j]);

      }

      }

      }

      return totalItems;

      };

      /* Get armor items */

      PHWarehouseManager.prototype.getArmors = function() {

      var totalItems = [];

      for (var i = 0; i < this._warehouses[this._lastActive].items.armor.length; i++) {

      for (var j = 0; j < $dataArmors.length; j++) {

      if ($dataArmors[j] != null && this._warehouses[this._lastActive].items.armor[i] == $dataArmors[j].id) {

      totalItems.push($dataArmors[j]);

      }

      }

      }

      return totalItems;

      };

      /* Get key items */

      PHWarehouseManager.prototype.getKeyItems = function() {

      var totalItems = [];

      for (var i = 0; i < this._warehouses[this._lastActive].items.keyItem.length; i++) {

      for (var j = 0; j < $dataItems.length; j++) {

      if ($dataItems[j] != null && this._warehouses[this._lastActive].items.keyItem[i] == $dataItems[j].id) {

      totalItems.push($dataItems[j]);

      }

      }

      }

      return totalItems;

      };

      /* Get the quantity for the corresponding item */

      PHWarehouseManager.prototype.getQuantity = function(item) {

      return this._warehouses[this._lastActive].qtty[this._lastCategory][item.id];

      };

      /* Checks whether or not the warehouse is already full */

      PHWarehouseManager.prototype.checkCapacity = function() {

      if (this._warehouses[this._lastActive].currentCapacity < this._warehouses[this._lastActive].maxCapacity) {

      return true;

      }

      return false;

      };

      /* Deposit on warehouse */

      PHWarehouseManager.prototype.deposit = function(item) {

      if (this.checkCapacity()) {

      var hasItem = false;

      if (this._warehouses[this._lastActive].items[this._lastCategory].indexOf(item.id) > -1) {

      hasItem = true;

      }

      if (hasItem) {

      this._warehouses[this._lastActive].qtty[this._lastCategory][item.id]++;

      } else {

      this._warehouses[this._lastActive].items[this._lastCategory].push(item.id);

      this._warehouses[this._lastActive].qtty[this._lastCategory][item.id] = 1;

      }

      this._warehouses[this._lastActive].currentCapacity++;

      }

      };

      /* Withdraw from a warehouse */

      PHWarehouseManager.prototype.withdraw = function(item) {

      var hasItem = false;

      var index = this._warehouses[this._lastActive].items[this._lastCategory].indexOf(item.id);

      if (index > -1) {

      hasItem = true;

      }

      if (hasItem) {

      this._warehouses[this._lastActive].qtty[this._lastCategory][item.id]--;

      if (this._warehouses[this._lastActive].qtty[this._lastCategory][item.id] == 0) {

      this._warehouses[this._lastActive].items[this._lastCategory].splice(index, 1);

      delete this._warehouses[this._lastActive].qtty[this._lastCategory][item.id];

      }

      this._warehouses[this._lastActive].currentCapacity--;

      }

      };

      /* Remove a warehouse */

      PHWarehouseManager.prototype.removeWarehouse = function(_sentence) {

      var matches = this.checkSentence(_sentence);

      if (matches != null) {

      if (this._warehouses.hasOwnProperty(matches[1])) {

      delete this._warehouses[matches[1]];

      }

      }

      };

      /* Check sentences coming from the arguments */

      PHWarehouseManager.prototype.checkSentence = function(_sentence) {

      var regExp = /\<([^)]+)\>/;

      return regExp.exec(_sentence);

      };

      /* ACCESSOR METHODS */

      /* Return the value of the maximum capacity of the warehouse for the given title */

      PHWarehouseManager.prototype.getMaxCapacity = function(title) {

      if (this._warehouses.hasOwnProperty(title)) {

      return this._warehouses[title].maxCapacity;

      }

      return 0;

      };

      /* Return the value of the current capacity of the warehouse for the given title */

      PHWarehouseManager.prototype.getCurrentCapacity = function(title) {

      if (this._warehouses.hasOwnProperty(title)) {

      return this._warehouses[title].currentCapacity;

      }

      return 0;

      };

      /* Return whether or not the warehouse for the given title exists */

      PHWarehouseManager.prototype.exist = function(title) {

      if (this._warehouses.hasOwnProperty(title) && this._warehouses[title] !== undefined) {

      return true;

      }

      return false;

      };

      /* ---------------------------------------------------------- *

      *                      LOADING PROCESS                       *

      * ---------------------------------------------------------- */

      /*

      * Creating PHWarehouse variable after loading the whole database

      */

      var _DataManager_loadDatabase_ = DataManager.loadDatabase;

      DataManager.loadDatabase = function() {

      _DataManager_loadDatabase_.call(this);

      PHWarehouse = new PHWarehouseManager();

      };

      /* Saves the warehouses when the player saves the game */

      var _DataManager_makeSaveContents_ = DataManager.makeSaveContents;

      DataManager.makeSaveContents = function() {

      var contents = _DataManager_makeSaveContents_.call(this);

      contents.phwarehouse = PHWarehouse._warehouses;

      return contents;

      };

      /* Retrieve the warehouses from the save content */

      var _DataManager_extractSaveContents_ = DataManager.extractSaveContents;

      DataManager.extractSaveContents = function(contents) {

      _DataManager_extractSaveContents_.call(this, contents);

      PHWarehouse = new PHWarehouseManager();

      PHWarehouse._warehouses = contents.phwarehouse;

      };

      var getAllArguments = function(args) {

      var str = args[1].toString();

      for (var i = 2; i < args.length; i++) {

      str += ' ' + args[i].toString();

      }

      return str;

      };

      var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;

      Game_Interpreter.prototype.pluginCommand = function(command, args) {

      _Game_Interpreter_pluginCommand.call(this, command, args);

      if (command === 'PHWarehouse') {

      switch (args[0]) {

      case 'create':

      PHWarehouse.createWarehouse(getAllArguments(args));

      break;

      case 'show':

      PHWarehouse.openWarehouse(getAllArguments(args));

      SceneManager.push(Scene_Warehouse);

      break;

      case 'remove':

      PHWarehouse.removeWarehouse(getAllArguments(args));

      break;

      }

      }

      };

      /* ---------------------------------------------------------- *

      *                       WINDOW PROCESS                       *

      * ---------------------------------------------------------- */

      function Window_WarehouseTitle() {

      this.initialize.apply(this, arguments);

      }

      Window_WarehouseTitle.prototype = Object.create(Window_Base.prototype);

      Window_WarehouseTitle.prototype.constructor = Window_WarehouseTitle;

      Window_WarehouseTitle.prototype.initialize = function() {

      Window_Base.prototype.initialize.call(this, 0, 0, Graphics.boxWidth, this.fittingHeight(1));

      this.refresh();

      };

      Window_WarehouseTitle.prototype.refresh = function() {

      this.contents.clear();

      this.changeTextColor(this.crisisColor());

      this.drawText(PHWarehouse._lastActive, 0, 0, Graphics.boxWidth, "center");

      };

      function Window_WarehouseOption() {

      this.initialize.apply(this, arguments);

      }

      Window_WarehouseOption.prototype = Object.create(Window_Selectable.prototype);

      Window_WarehouseOption.prototype.constructor = Window_WarehouseOption;

      Window_WarehouseOption.prototype.initialize = function() {

      Window_Selectable.prototype.initialize.call(this, 0, this.fittingHeight(1), Graphics.boxWidth, this.fittingHeight(1));

      this.withdrawText = withdrawText;

      this.depositText = depositText;

      this.refresh();

      this.select(0);

      this.activate();

      };

      Window_WarehouseOption.prototype.maxItems = function() {

      return 2;

      };

      Window_WarehouseOption.prototype.maxCols = function() {

      return 2;

      };

      Window_WarehouseOption.prototype.changeOption = function() {

      PHWarehouse._lastOption = this._index;

      };

      Window_WarehouseOption.prototype.refresh = function() {

      var rectWithdraw = this.itemRectForText(0);

      var rectDeposit = this.itemRectForText(1);

      this.drawText(this.withdrawText, rectWithdraw.x, rectWithdraw.y, rectWithdraw.width, "center");

      this.drawText(this.depositText, rectDeposit.x, rectDeposit.y, rectDeposit.width, "center");

      };

      function Window_WarehouseCategory() {

      this.initialize.apply(this, arguments);

      }

      Window_WarehouseCategory.prototype = Object.create(Window_ItemCategory.prototype);

      Window_WarehouseCategory.prototype.constructor = Window_WarehouseCategory;

      Window_WarehouseCategory.prototype.initialize = function() {

      Window_ItemCategory.prototype.initialize.call(this);

      this.y = this.fittingHeight(3);

      this.deselect();

      this.deactivate();

      };

      Window_WarehouseCategory.prototype.changeCategory = function() {

      PHWarehouse._lastCategory = this.currentSymbol() || "item";

      };

      Window_WarehouseCategory.prototype.setItemWindow = function(itemWindow) {

      this._itemWindow = itemWindow;

      this.update();

      };

      Window_WarehouseCategory.prototype.update = function() {

      Window_ItemCategory.prototype.update.call(this);

      this.changeCategory();

      this._itemWindow.refresh();

      };

      function Window_WarehouseItemList() {

      this.initialize.apply(this, arguments);

      }

      Window_WarehouseItemList.prototype = Object.create(Window_ItemList.prototype);

      Window_WarehouseItemList.prototype.constructor = Window_WarehouseItemList;

      Window_WarehouseItemList.prototype.initialize = function() {

      Window_ItemList.prototype.initialize.call(this, 0, this.fittingHeight(5), Graphics.boxWidth, Graphics.boxHeight - this.fittingHeight(7));

      };

      Window_WarehouseItemList.prototype.isCurrentItemEnabled = function() {

      if (this._data.length > 0) {

      if (PHWarehouse._lastOption == 1 && PHWarehouse.checkCapacity()) {

      return true;

      } else if (PHWarehouse._lastOption == 0) {

      return true;

      } else {

      return false;

      }

      }

      return false;

      };

      Window_WarehouseItemList.prototype.makeWarehouseItemList = function() {

      var data = PHWarehouse.getItems();

      this._data = data.filter(function(item) {

      return this.includes(item);

      }, this);

      if (this.includes(null)) {

      this._data.push(null);

      }

      };

      Window_WarehouseItemList.prototype.loadItems = function() {

      // Deposit

      if (PHWarehouse._lastOption == 1) {

      this.makeItemList();

      }

      // Withdraw

      else if (PHWarehouse._lastOption == 0) {

      this.makeWarehouseItemList();

      }

      };

      Window_WarehouseItemList.prototype.drawItem = function(index) {

      var item = this._data[index];

      if (item) {

      var numberWidth = this.numberWidth();

      var rect = this.itemRect(index);

      rect.width -= this.textPadding();

      this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);

      if (PHWarehouse._lastOption == 1) {

      this.drawItemNumber(item, rect.x, rect.y, rect.width);

      } else if (PHWarehouse._lastOption == 0) {

      this.drawWarehouseItemNumber(item, rect.x, rect.y, rect.width);

      }

      }

      };

      Window_WarehouseItemList.prototype.drawWarehouseItemNumber = function(item, x, y, width) {

      var qtty = PHWarehouse.getQuantity(item);

      if (typeof Yanfly !== "undefined") {

      this.contents.fontSize = Yanfly.Param.ItemQuantitySize;

      this.drawText('\u00d7' + qtty, x, y, width, 'right');

      this.resetFontSettings();

      } else {

      this.drawText(':', x, y, width - this.textWidth('00'), 'right');

      this.drawText(qtty, x, y, width, 'right');

      }

      };

      Window_WarehouseItemList.prototype.refresh = function() {

      this.contents.clear();

      this.loadItems();

      this.drawAllItems();

      };

      Window_WarehouseItemList.prototype.moveItem = function() {

      // Deposit

      if (PHWarehouse._lastOption == 1) {

      if (PHWarehouse.checkCapacity()) {

      PHWarehouse.deposit(this.item());

      $gameParty.loseItem(this.item(), 1);

      }

      }

      // Withdraw

      else if (PHWarehouse._lastOption == 0) {

      PHWarehouse.withdraw(this.item());
yinzord(银阼) - 2019-07-10 0 人
。。。。。。。
class Main {
	public static void main(String[] args) {
		System.out.println("Create new Cupboard() in main");
        new Cupboard();
        System.out.println("Create new Cupboard() in main");
        new Cupboard();
        table.f2(1);
        cupboard.f3(1);
	}
    static Table table = new Table();
    static Cupboard cupboard = new Cupboard();
}

class Bowl {
    Bowl(int marker) {
        System.out.println("Bowl (" + marker + ")");
    }
    void f1(int marker) {
        System.out.println(" f1 -> Bowl (" + marker + ")");
    }
}

class Table {
    static Bowl bow = new Bowl(1);
    Table() {
        System.out.println("Table()");
    }
    void f2(int marker) {
        System.out.println(" f2 -> Table (" + marker + ")");
    }
    static Bowl bowl2 = new Bowl(2);
}

class Cupboard {
    Bowl bowl3 = new Bowl(3);
    static Bowl bowl4 = new Bowl(4);
    Cupboard() {
        System.out.println("Cupboard()");
        bowl4.f1(2);
    }
    void f3(int marker) {
        System.out.println("Cupboard() -> f3 " + "marker" + marker);
    }
    static Bowl bowl5 = new Bowl(5);
}
invoker0imba(前端大神) - 2019-07-04 0 人
静态数据初始化
class Main {
	public static void main(String[] args) {
		System.out.println("Hello JSRUN!   \n\n         - from JAVA .");
	int a = 10;
    int b = a+5;
    System.out.println(b);
    }
}
busizhiya(桥) - 2019-06-25 0 人
计算 测试123
class Main {
	public static void main(String[] args) {
		System.out.println("Hello JSRUN!   \n\n         - from JAVA .");
	}

    public int majorityElement(int[] nums) {

        int count = 1;
        int res = nums[0];
        
        for(int i = 0; i < nums.length; i++){
            if(count == 0){
                res = nums[i];
            }else {
                if(res == nums[i]){
                    count ++;
                }else{
                    count --;
                }
            }
        }   

        return res;
    }

    public int majorityElement_1(int[] nums) {

        Stack<Integer> stack = new Stack<>();
        for(int i : nums){
            if(stack.isEmpty() || i == stack.peek()){
                stack.push(i);
            }else{
                stack.pop();
            }
        }
        
        return stack.peek();
    }
}
toryang(Toryang) - 2019-06-17 0 人
LeetCode 169. 求众数
class Main {
	public static void main(String[] args) {
		System.out.println("Hello JSRUN!   \n\n         - from JAVA .");
	}

    public int maxProduct(int[] nums) {
        int max = Integer.MIN_VALUE, imax = 0, imin = 0;

        for(int i = 0; i < nums.length; i++){
            if(nums[i] < 0){
                int temp = imax;
                imax = imin;
                imin = temp;
            }
            imax = Math.max(imax*nums[i],nums[i]);
            imin = Math.min(imin*nums[i],nums[i]);

            max = Math.max(max,imax);
        }
        return max;
    }

    public int maxProduct_1(int[] nums) {

        int[][] dp = new int[2][2];
        dp[0][0] = nums[0];
        dp[0][1] = nums[0];
        int max = nums[0];

        for(int i = 1; i < nums.length; i++){
            int x = i % 2;
            int y = (i - 1) % 2;

            dp[x][0] = Math.max(Math.max(nums[i] * dp[y][1], nums[i] * dp[y][0]), dp[y][0]);
            dp[x][1] = Math.min(Math.min(nums[i] * dp[y][1], nums[i] * dp[y][0]), dp[y][0]);

            max = Math.max(dp[x][0],max);
        }

        return max;
    }
    
}
toryang(Toryang) - 2019-06-17 0 人
LeetCode 152. 乘积最大子序列
没有了
1/7 下一页