Esempio n. 1
0
 /**
  * 真正的校验逻辑,通过配置的正则表达式校验字段是否符合规范
  *
  * @param key
  *            待校验字段
  * @param dc
  * @param must
  *            字段是否是必须的
  * @throws Exception
  */
 protected static function check($key, $map, $must)
 {
     $log = new Logger();
     $value = $map->get($key);
     $tValue = $value;
     if (empty($value)) {
         // 必须字段为空,抛出异常
         if ($must) {
             die("The parameters of the request " . $key . " can't be empty");
         }
     } else {
         if (count(CheckReqDataAndEncrypt::$regexkeysarray) <= 0) {
             $log->logInfo("loading mapping_regex.ini");
             CheckReqDataAndEncrypt::$regexkeysarray = parse_ini_file("mapping_regex.ini");
         }
         $regex = CheckReqDataAndEncrypt::$regexkeysarray["Regex." . $key];
         if (empty($regex)) {
             $log->logInfo("The parameters of the request " . $key . " not configured regular validation rules");
             return;
         }
         // 不符合正则表达式
         if (!preg_match($regex, $tValue)) {
             $log->logInfo("Request parameters [" . $key . "(" . $tValue . ")] format or value can not match the regular rules [" . $regex . "]");
             die("Request parameters [" . $key . "(" . $tValue . ")] format or value is not correct");
         } else {
             $log->logInfo("Request parameters [" . $key . "(" . $tValue . ")] format or value match the regular rules [" . $regex . "]");
         }
     }
 }
Esempio n. 2
0
 /**
  * 返回组装好的数据给商户
  * @param unknown_type $appname
  * @param unknown_type $map
  * @param unknown_type $method
  * @return ReqData
  */
 public function makeRequestData($appname, $map, $method)
 {
     $log = new Logger();
     $funcode = StringUtil::trim($map->get("service"));
     $reqData = new ReqData();
     //对请求数据进行有效性验证
     CheckReqDataAndEncrypt::doCheck($map);
     //敏感字段加密
     $map = CheckReqDataAndEncrypt::doEncrypt($map);
     //获取请求数据签名明文串
     $plain = $this->getSortPlain($map);
     //获取请求数据签名密文串
     $sign = $this->getSignData($map);
     $log->logInfo("Request platform way=" . $method);
     $log->logInfo("Request platform signature string=" . $sign);
     $log->logInfo("Clear information request platform=" . $plain);
     //获取GET方式请求数据对象
     if ($method == method_get) {
         //获取平台URL
         $url = $this->getUrlForV4($appname);
         //获取请求参数
         $param = StringUtil::getSortParameter($map);
         $reqData->setUrl($url . "?" . $param . '&sign=' . urlencode($sign));
         $log->logInfo("The service " . $funcode . " request platform to get the address url=" . $url . "?" . $param . '&sign=' . $sign);
         //获取POST方式请求数据对象
     } else {
         if ($method == method_post) {
             $url = $this->getUrlForV4($appname);
             $log->logInfo("The service " . $funcode . " request platform to post the address url=" . $url);
             $reqData->setUrl($url);
             $map->put("sign", $sign);
             $reqData->setField($map);
         } else {
             die("Not found " . $method . "type processing class");
         }
     }
     $reqData->setPlain($plain);
     $reqData->setSign($sign);
     return $reqData;
 }