订单查询
服务商模式接入文档:https://pay.weixin.qq.com/wiki/doc/api/micropay_sl.php?chapter=9_2
商户模式接入文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_2

@param isSandbox
是否是沙盒环境
@param params
请求参数
@return {String}
169138
public static String orderQuery(boolean isSandbox, Map<String, String> params) {
		if (isSandbox)
			return doPost(ORDERQUERY_SANDBOXNEW_URL, params);
		return doPost(ORDERQUERY_URL, params);
	}
609036
public static MicropayResult payMicropay(Micropay micropay,String key){
		Map<String,String> map = MapUtil.objectToMap(micropay);
		//@since 2.8.14 detail 字段签名处理
		if(micropay.getDetail() != null){
			map.put("detail",JsonUtil.toJSONString(micropay.getDetail()));
		}
		String sign = SignatureUtil.generateSign(map,micropay.getSign_type(),key);
		micropay.setSign(sign);
		String closeorderXML = XMLConverUtil.convertToXML(micropay);
		HttpUriRequest httpUriRequest = RequestBuilder.post()
				.setHeader(xmlHeader)
				.setUri(baseURI()+ "/pay/micropay")
				.setEntity(new StringEntity(closeorderXML,Charset.forName("utf-8")))
				.build();
		return LocalHttpClient.executeXmlResult(httpUriRequest,MicropayResult.class,micropay.getSign_type(),key);
	}
209297
public static String orderRefundQuery(boolean isSandbox, Map<String, String> params) {
		if (isSandbox)
			return doPost(REFUNDQUERY_SANDBOXNEW_URL, params);
		return doPost(REFUNDQUERY_URL, params);
	}
80330
public function getPaySign($openid='',$body,$attach,$out_trade_no,$total_fee,$notify_url,$time_start=0,$time_expire=0){
        $wxpay = new PayLib\WxPayApi($this->type);
        //统一下单
        $input = new PayLib\WxPayUnifiedOrder();

        if($this->type === 'mp'){
            if(empty($openid)){
                throw new Exception('请传入openid','OPENID_EMPTY');
            }
            $input->SetOpenid($openid);
            $input->SetTrade_type('JSAPI');#接口
        }
        elseif($this->type === 'app'){
            $input->SetTrade_type('APP');#接口
        }

        $input->SetBody($body);//设置商品或支付单简要描述
        $input->SetOut_trade_no($out_trade_no);#设置单号
        $input->SetTotal_fee($total_fee);#设置支付金额
        $input->SetAttach($attach);//自定义的参数

        $input->SetNotify_url($notify_url);#回调地址


        if($time_start!==0){
            $input->SetTime_start($time_start);         //交易起始时间
        }

        if($time_expire!==0){
            $input->SetTime_expire($time_expire);       //交易结束时间
        }

        $order = PayLib\Wxpayapi::unifiedOrder($input);#生成订单

        if(empty($order['return_code'])||$order['return_code']!=='SUCCESS'){
            throw new Exception('微信错误,'.$order['return_msg'],'WECHAT_ERROR');
        }

        if(empty($order['result_code'])||$order['result_code']!=='SUCCESS'){
            throw new Exception('生成微信单号失败,'.$order['return_msg'],'WECHAT_ERROR');
        };

        if(!array_key_exists("appid", $order)|| !array_key_exists("prepay_id", $order)|| $order['prepay_id'] == ""){
            throw new Exception("参数错误",'PARAMS_ERROR');
        }

        if($this->type == 'mp'){
            $jsObj=new PayLib\WxPayJsApiPay();
            $jsObj->SetAppid($order["appid"]);
            $timeStamp = time();
            $jsObj->SetTimeStamp("$timeStamp");
            $jsObj->SetNonceStr(PayLib\WxPayApi::getNonceStr());
            $jsObj->SetSignType("MD5");
            $jsObj->SetPackage("prepay_id=" . $order['prepay_id']);
            $jsObj->SetPaySign($jsObj->MakeSign());

            $jsApiParameters = json_encode($jsObj->GetValues());
            if (!$jsApiParameters) {
                throw new Exception('微信接口对接失败','WECHAT_ERROR');
            }
        }
        elseif($this->type == 'app'){
            $appObj=new PayLib\WxPayAppApiPay();
            $appObj->SetAppid($order["appid"]);
            $timeStamp = time();
            $appObj->SetTimeStamp("$timeStamp");
            $appObj->SetNonceStr(PayLib\WxPayApi::getNonceStr());
            $appObj->SetPackage("Sign=WXPay");
            $appObj->SetPartnerId(PayLib\WxPayConfig::$MCHID);
            $appObj->SetPrepayId($order['prepay_id']);
            $appObj->SetSign();

            $getValues=$appObj->GetValues();
            $getValues['orderid']=$out_trade_no;

            $jsApiParameters = json_encode($getValues);
            //log_message('error',$jsApiParameters);
            if (!$jsApiParameters) {
                throw new Exception('微信接口对接失败','WECHAT_ERROR');
            }
        }
        else{
            throw new Exception('位置类型','TYPE_ERROR');
        }

        return $jsApiParameters;
    }
551625
public function QPayOrderQuery($params = array()){
        /*        //入参
                $params = array();
                $params["out_trade_no"] = "20160512161914_BBC";
                $params["sub_mch_id"] = "1900005911";*/
        if (empty($params["out_trade_no"])){
            throw new Exception('商户订单号参数不能缺少' ,'OUT_TRADE_NO_MUST_INPUT');
        }
        if (empty($params["sub_mch_id"])){
            throw new Exception('sub_mch_id不能缺少' ,'FEE_TYPE');
        }

        //api调用
        $qpayApi = new QpayMchAPI('https://qpay.qq.com/cgi-bin/pay/qpay_order_query.cgi', null, 10);
        $qpayApi->setMchId('1490434181');
        $qpayApi->setMchKey('8525638f86969d1de5c51ad0494f4f13');
        $ret = $qpayApi->reqQpay($params);
        return QpayMchUtil::xmlToArray($ret);
    }
406205
def posted_values(param)
    
      if param.kind_of?(Hash) and param.has_key?('year') and param.has_key?('month')
        year = param['year']
        month = param['month']
        if month.blank? or year.blank?
          values = ''
        else
          values = [Date.new(year.to_i, month.to_i, 1).strftime('%m/%d/%Y')]  # for mm/yy drop downs
        end
      elsif param.kind_of?(Hash)
        # from Hash with multiple answers per question
        values = param.values.map {|v| CGI.unescape(v)}
      elsif param.kind_of?(String)
        values = [CGI.unescape(param)]
      end
    
      # Hash may contain empty string to force post for no checkboxes
  #    values = values.reject {|r| r == ''}
    end
925092
public String getQueryString(MultiValueMap<String, String> params) {
		if (params.isEmpty()) {
			return "";
		}
		StringBuilder query = new StringBuilder();
		Map<String, Object> singles = new HashMap<>();
		for (String param : params.keySet()) {
			int i = 0;
			for (String value : params.get(param)) {
				query.append("&");
				query.append(param);
				if (!"".equals(value)) { // don't add =, if original is ?wsdl, output is
					// not ?wsdl=
					String key = param;
					// if form feed is already part of param name double
					// since form feed is used as the colon replacement below
					if (key.contains("\f")) {
						key = (FORM_FEED_PATTERN.matcher(key).replaceAll("\f\f"));
					}
					// colon is special to UriTemplate
					if (key.contains(":")) {
						key = COLON_PATTERN.matcher(key).replaceAll("\f");
					}
					key = key + i;
					singles.put(key, value);
					query.append("={");
					query.append(key);
					query.append("}");
				}
				i++;
			}
		}

		UriTemplate template = new UriTemplate("?" + query.toString().substring(1));
		return template.expand(singles).toString();
	}
389132
public static String packageSign(Map<String, String> params, boolean urlEncoder) {
		// 先将参数以其参数名的字典序升序进行排序
		TreeMap<String, String> sortedParams = new TreeMap<String, String>(params);
		// 遍历排序后的字典，将所有参数按"key=value"格式拼接在一起
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (Entry<String, String> param : sortedParams.entrySet()) {
			String value = param.getValue();
			if (StrKit.isBlank(value)) {
				continue;
			}
			if (first) {
				first = false;
			} else {
				sb.append("&");
			}
			sb.append(param.getKey()).append("=");
			if (urlEncoder) {
				try {
					value = urlEncode(value);
				} catch (UnsupportedEncodingException e) {
				}
			}
			sb.append(value);
		}
		return sb.toString();
	}
473588
function _check(&$data, $param)
    {
        foreach ($param as $k => $p)
        {
            if (!isset($data[$k]))
            {
                if (isset($p['require']) and $p['require'])
                {
                    self::raise('param require');
                }
                else
                {
                    continue;
                }
            }

            if (isset($p['type']))
            {
                $data[$k] = Validate::$p['type']($data[$k]);
                if ($data[$k] === false)
                {
                    self::raise();
                }

                //最小值参数
                if (isset($p['min']) and is_numeric($data[$k]) and $data[$k] < $p['min'])
                {
                    self::raise('num too small');
                }
                //最大值参数
                if (isset($p['max']) and is_numeric($data[$k]) and $data[$k] > $p['max'])
                {
                    self::raise('num too big');
                }

                //最小值参数
                if (isset($p['short']) and is_string($data[$k]) and mb_strlen($data[$k]) < $p['short'])
                {
                    self::raise('string too short');
                }
                //最大值参数
                if (isset($p['long']) and is_string($data[$k]) and mb_strlen($data[$k]) > $p['long'])
                {
                    self::raise('string too long');
                }

                //自定义的正则表达式
                if ($p['type'] == 'regx' and isset($p['regx']) and preg_match($p['regx'], $data[$k]) === false)
                {
                    self::raise();
                }
            }
        }
        //如果为拒绝模式，所有不在过滤参数$param中的键值都将被删除
        if ($this->mode == 'deny')
        {
            $allow = array_keys($param);
            $have = array_keys($data);
            foreach ($have as $ha)
            {
                if (!in_array($ha, $allow))
                {
                    unset($data[$ha]);
                }
            }
        }
    }
441063
public static String getRequestPayloadOutput(Request params, File file) {
        StringBuilder payload = new StringBuilder();
        String uuid = getUUID();
        payload.append(ONCLICK_TOGGLE).append(uuid).append("\")'>Toggle Payload</a> ");
        payload.append(SPAN_ID).append(uuid).append(DISPLAY_NONE);
        if (params != null && params.getJsonPayload() != null) {
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            payload.append(DIV);
            payload.append(formatHTML(gson.toJson(params.getJsonPayload())));
            payload.append(END_DIV);
        }
        if (params != null && params.getMultipartData() != null) {
            for (Map.Entry<String, Object> entry : params.getMultipartData().entrySet()) {
                payload.append(DIV);
                payload.append(entry.getKey());
                payload.append(" : ");
                payload.append(entry.getValue());
                payload.append(END_DIV);
            }
        }
        if (file != null) {
            payload.append("<div> with file: <a href='file:///").append(file.getAbsoluteFile()).append("'>").append(file.getName()).append("</a></div>");
        }
        payload.append(END_SPAN);
        if (payload.toString().equals(ONCLICK_TOGGLE + uuid + "\")'>Toggle Payload</a> " + SPAN_ID + uuid + DISPLAY_NONE + END_SPAN)) {
            return "";
        } else {
            return payload.toString();
        }
    }
1305304
private String buildPayForm(Map<String, String> payParams) {
        StringBuilder form = new StringBuilder();

        form.append("<form id=\"pay_form\" name=\"pay_form\"").append(" action=\"" + Alipay.GATEWAY).append(AlipayField.INPUT_CHARSET+"=").append(alipay.inputCharset).append("\" method=\"POST\">");
        for (Map.Entry<String, String> param : payParams.entrySet()){
            form.append("<input type=\"hidden\" name=\"")
                    .append(param.getKey()).append("\" value=\"").append(param.getValue()).append("\" />");
        }
        form.append("<input type=\"submit\" value=\"去支付\" style=\"display:none;\" />");
        form.append("</form>");
        form.append("<script>document.forms['pay_form'].submit();</script>");

        return form.toString();
    }
211994
private static String getNoSign(Map<String, Object> params, boolean includeEmptyParam) {
        //对参数按照key做升序排序，对map的所有value进行处理，转化成string类型
        //拼接成key=value&key=value&....格式的字符串
        StringBuilder content = new StringBuilder();

        // 按照key做排序
        List<String> keys = new ArrayList<String>(params.keySet());
        Collections.sort(keys);

        String value = null;
        Object object = null;
        boolean isFirstParm = true;
        for (int i = 0; i < keys.size(); i++) {
            String key = (String) keys.get(i);
            object = params.get(key);

            if (object == null) {
                value = "";
            }else if (object instanceof String) {
                value = (String) object;
            } else {
                value = String.valueOf(object);
            }

            if (includeEmptyParam || !TextUtils.isEmpty(value)) {
                content.append((isFirstParm ? "" : "&") + key + "=" + value);
                isFirstParm = false;
            } else {
                continue;
            }
        }

        //待签名的字符串
        return content.toString();
    }
11180
@Override
    public NutMap postPay(String url, String key, Map<String, Object> params) {
        params.remove("sign");
        String sign = WxPaySign.createSign(key, params);
        params.put("sign", sign);
        Request req = Request.create(url, METHOD.POST);
        req.setData(Xmls.mapToXml(params));
        Response resp = Sender.create(req).send();
        if (!resp.isOK())
            throw new IllegalStateException("postPay, resp code=" + resp.getStatus());
        return Xmls.xmlToMap(resp.getContent("UTF-8"));
    }
848544
private static function _parseIfXxxWith1ParamMultiInts($paramstr, $validatorName)
    {
        $params = explode(',', $paramstr);
        $c = count($params);
        if ($c < 2)
            return false;

        $varName = $params[0];
        $vals = [];
        for ($i = 1; $i < $c; $i++) {
            $intVal = $params[$i];
            self::validateInt($intVal, "“$validatorName:${paramstr}”中“${varName}”后面必须全部是整数，实际上却包含了“${intVal}”");
            $vals[] = intval($intVal);
        }
        return [$varName, $vals];
    }
905592
protected static InputStream downloadMaterial(String url, String params) throws IOException {
		URL _url = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
		// 连接超时
		conn.setConnectTimeout(25000);
		// 读取超时 --服务器响应比较慢，增大时间
		conn.setReadTimeout(25000);
		conn.setRequestMethod("POST");
		conn.setRequestProperty("Content-Type", "Keep-Alive");
		conn.setRequestProperty("User-Agent", DEFAULT_USER_AGENT);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		conn.connect();
		if (StrKit.notBlank(params)) {
			OutputStream out = conn.getOutputStream();
			out.write(params.getBytes(Charsets.UTF_8));
			out.flush();
			IOUtils.closeQuietly(out);
		}
		return conn.getInputStream();
	}
163882
private static StringMap filterParam(StringMap params) {
        final StringMap ret = new StringMap();
        if (params == null) {
            return ret;
        }
        params.forEach(new StringMap.Consumer() {
            @Override
            public void accept(String key, Object value) {
                if (value == null) {
                    return;
                }
                String val = value.toString();
                if ((key.startsWith("x:") || key.startsWith("x-qn-meta-")) && !val.equals("")) {
                    ret.put(key, val);
                }
            }
        });
        return ret;
    }
42244
@SuppressWarnings("rawtypes")
    public static String createSign(String key, Map<String, Object> params) {
        SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
        Set es = params.entrySet();
        Iterator it = es.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            String k = (String) entry.getKey();
            Object v = entry.getValue();
            parameters.put(k, v);
        }
        StringBuffer sb = new StringBuffer();
        Set es2 = parameters.entrySet();//accsii升序排序
        Iterator it2 = es2.iterator();
        while (it2.hasNext()) {
            Map.Entry entry = (Map.Entry) it2.next();
            String k = (String) entry.getKey();
            Object v = entry.getValue();
            if (null != v && !"".equals(v)
                    && !"sign".equals(k) && !"key".equals(k)) {
                sb.append(k + "=" + v + "&");
            }
        }
        sb.append("key=" + key);
        String sign = Lang.md5(sb.toString()).toUpperCase();
        return sign;
    }