mReqHost = BASE_SITE_URL; } else { $this->mReqHost = 'https://www.xyzshops.cn'; } } public static function setUpBeforeClass(): void { Base::run_util(); } public function testFactory() { $providers = refill\RefillFactory::instance(); } public function testRefillPhone() { // global $config; // $providers = new \refill\beixts\RefillPhone($config['phone_providers']['beixts']); // $resp = $providers->add(13699279618,4,50,['order_sn' => '200649600557718886']); //{"ack":"success","message":{"order_number":13281474,"charged_amount":"48.750","shipping_status":"5","shipping_status_desc":"未发货"}} //$_POST='{"order_number":13281474,"shipping_status":1,"shipping_status_desc":"已发货","shipping_status_message":"","sign":"05863f9931ed69a70e456222f057dfdd","voucher":"110103307162012081746340295254","vouchertype":"","voucherurl":"","tradeNo":"200649600557718888"}'; $params['order_number'] = 15566432; $params['shipping_status'] = 1; $params['shipping_status_desc'] = '已发货'; $params['shipping_status_message'] = ''; $params['sign'] = '53aaf3dee6b0dd17b081073a0df7019c'; $params['voucher'] = '110103307162012081746340295254'; $params['vouchertype'] = ''; $params['voucherurl'] = ''; $params['tradeNo'] = '200649600557718887'; $ret = refill\RefillFactory::instance()->notify('beixt',$params); } public function testSuhxVerify() { $data = 'onlystr=190661874318128632&sign=9eb60765c356341fd41c9bec6526f46a&amt=1000¬ifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=25940&cardno=1000111100012304048&orgid=1590993600&status=2'; $url = "http://192.168.1.220/mobile/refill_suhc.php?" . $data; $resp = http_request($url); } public function testUrl() { $data = 'onlystr=190661874318128632&sign=9eb60765c356341fd41c9bec6526f46a&amt=1000¬ifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=25940&cardno=1000111100012304048&orgid=1590993600&status=2'; $params = preg_split('/&/', $data); foreach ($params as $pair) { $kv = explode('=', $pair); $count = count($kv); if($count === 1) { $key = $kv[0]; $val = ""; } elseif($count === 2) { $key = $kv[0]; $val = $kv[1]; } else { continue; } Log::record("{$key}:{$val}",Log::DEBUG); } } public function testAddoil() { $url = $this->mReqHost . "/mobile/index.php"; $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php'; $params = ['mchid' => 1, 'cardno' => '1000111100020445281', 'amount' => "100", "act"=>"refill", "op"=>"add", 'order_sn' => "13281478", 'notifyurl'=> $notifyurl]; $resp = $this->send_md5($url,$params); Log::record($resp,Log::DEBUG); } public function testAddPhoe() { $url = $this->mReqHost . "/mobile/index.php"; $params = ['mchid' => 1, 'cardno' => '15120035568', 'amount' => "50", "act"=>"refill", "op"=>"add", 'order_sn' => "13281475", 'notifyurl'=> $this->mReqHost . "/mobile/beixt_notify.php"]; $resp = $this->send_md5($url,$params); Log::record($resp,Log::DEBUG); } public function testGoods() { // $req_url = 'https://www.xyzshops.cn/mobile/index.php'; // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php'; $req_url = BASE_SITE_URL . '/mobile/index.php'; $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php'; $params = ['mchid' => 1, "act"=>"refill", "op"=>"goods"]; $resp = $this->send_md5($req_url,$params); } public function testQueryFactory() { refill\RefillFactory::instance()->query(295); } public function testQuery() { //$req_url = 'https://www.xyzshops.cn/mobile/index.php'; // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php'; $req_url = BASE_SITE_URL . '/mobile/index.php'; $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php'; $params = ['mchid' => 1, "act"=>"refill", "op"=>"query", 'order_sn' => "13281476"]; $resp = $this->send_md5($req_url,$params); } public function testRemoveSession() { $resp = http_request(BASE_SITE_URL . "/mobile/signature.php",[],'POST'); } public function testSuhcCB() { // $notifyurl = BASE_SITE_URL . "/mobile/refill_suhc.php"; $notifyurl = "https://www.xyzshops.cn/mobile/refill_suhc.php"; // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php"; $params = ['onlystr' => '920660917672249741', 'amt' => 100, 'jdno'=>'', 'notifyurl' => $notifyurl, 'cardtype' => 'Sinoepc', 'batchid' => 18512, 'cardno' => '1000111100020445281', 'orgid' => '1590993600', 'status' => 2]; $sign = $this->md5_sign($params); $params['sign'] = $sign; $resp = http_request($notifyurl,$params,'POST'); Log::record($resp,Log::DEBUG); } protected function check_empty($value) { if (!isset($value)) return true; if ($value === null) return true; if (trim($value) === "") return true; return false; } private function md5_sign($params) { ksort($params); $body = ""; $i = 0; foreach ($params as $k => $v) { if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) { if ($i == 0) { $body .= "{$k}" . "=" . urldecode($v); } else { $body .= "&" . "{$k}" . "=" . urldecode($v); } $i++; } } $body .= "&key=7yDCLS6S2KzSAJQOUc3vsa"; return md5($body); } public function testCallMech() { $logic = Logic('queue'); $logic->NotifyMerchantComplete(['order_id' => 289]); } private function send($url,$params) { $mchid = $params['mchid']; $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem"; $key = file_get_contents($pri_key); $pri = openssl_get_privatekey($key); $body = $this->body($params); openssl_sign($body, $signed, $pri); $sign = base64_encode($signed); $params['sign'] = $sign; $resp = http_request($url,$params,'POST'); Log::record("resp:{$resp}",Log::DEBUG); } private function send_md5($url,$params) { $body = $this->body($params); $body .= "&key=1ff02223b771c0414468c8892151c602"; $params['sign'] = md5($body); $resp = http_request($url,$params,'POST'); Log::record("resp:{$resp}",Log::DEBUG); return $resp; } public function testCardType() { $cardno = '1000111100021211884'; $ret = preg_match( '/^1[0-9]{18}$/',$cardno,$matches); } public function testMtrand() { } public function testHttpRefill() { $mchid = '000001'; $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem"; $key = file_get_contents($pri_key); $pri = openssl_get_privatekey($key); $params = ['MCHID' => $mchid,'cardno' => '1000111100021211884','amt' => "100","act"=>"refill","op"=>"addoil"]; $body = $this->body($params); openssl_sign($body, $signed, $pri); $sign = base64_encode($signed); $params['sign'] = $sign; $resp = http_request(BASE_SITE_URL . "/mobile/index.php",$params,'POST'); } private function body($params) { ksort($params); $stringToBeSigned = ""; $i = 0; foreach ($params as $k => $v) { if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) { if ($i == 0) { $stringToBeSigned .= "{$k}" . "=" . urlencode($v); } else { $stringToBeSigned .= "&" . "{$k}" . "=" . urlencode($v); } $i++; } } return $stringToBeSigned; } private function checkEmpty($value) { if (!isset($value)) return true; if ($value === null) return true; if (trim($value) === "") return true; return false; } public function testKsort() { $age= ["Peter"=>"35","Ben"=>"37","Joe"=>"43"]; ksort($age); foreach($age as $x=>$x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "
"; } } public function testip(){ $model_merchant = Model('merchant'); $merchant_info = $model_merchant->getMerchantInfo(array('mchid' => 1)); $ipwhitelist = unserialize($merchant_info['ip_white_list']); $res = json_encode($ipwhitelist); } }