12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106 |
- <?php
- use PHPUnit\Framework\TestCase;
- use const mtopcard\SinopecCard;
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_CORE_PATH . '/framework/function/http.php');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
- const LocalTest = 1;
- const NetTest = 2;
- const CurrentTest = LocalTest;
- class TestRefill extends TestCase
- {
- private $mReqHost;
- private $mKey;
- private $mMchid;
- public function __construct(?string $name = null, array $data = [], $dataName = '')
- {
- parent::__construct($name, $data, $dataName);
- if (CurrentTest == LocalTest) {
- $this->mReqHost = BASE_SITE_URL;
- $this->mMchid = 1;
- $this->mKey = '1ff02223b771c0414468c8892151c602';
- } else {
- $this->mReqHost = 'https://www.xyzshops.cn';
- $this->mMchid = 1092;
- $this->mKey = '210fe406954220f56085997d6a4c5b80';
- }
- }
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- refill\RefillFactory::instance();
- }
- public function testFactory()
- {
- $providers = refill\RefillFactory::instance();
- }
- private function make_sn()
- {
- return mt_rand(1000, 9999)
- . sprintf('%010d', time())
- . sprintf('%06d', (float)microtime() * 1000000);
- }
- public function testRandomMobile()
- {
- $no = "1" . mt_rand(1, 9999999999);
- Log::record("phone no={$no}",Log::DEBUG);
- }
- public function testBJBAddPhone()
- {
- $providers = new refill\bjb\RefillPhone([]);
- for ($i = 3; $i > 0; --$i) {
- $resp = $providers->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
- $resp = $providers->add(18500608333, 4, 10, ['order_sn' => $this->make_sn()]);
- $resp = $providers->add(18510683168, 4, 10, ['order_sn' => $this->make_sn()]);
- $resp = $providers->add(18513846008, 4, 10, ['order_sn' => $this->make_sn()]);
- $resp = $providers->add(18518237398, 4, 10, ['order_sn' => $this->make_sn()]);
- }
- }
- public function testOilticket()
- {
- $providers = new refill\bjb\RefillPhone([]);
- }
- public function testBjbRet()
- {
- $resp = '0|提交成功|14936.8600';
- $resp = explode('|' , $resp);
- }
- public function testIpWhiteList()
- {
- $x = serialize(['47.99.57.105']);
- $ips = unserialize('a:1:{i:0;s:12:"47.99.57.105";}');
- if (!empty($ips)) {
- $addr = '47.99.57.105';
- Log::record("request ip:{$addr}", Log::DEBUG);
- if (!in_array($addr, $ips)) {
- throw new Exception("请求地址不在白名单中");
- }
- }
- }
- public function testBaizePhone()
- {
- $providers = new refill\baizeyd\RefillPhone([]);
- // $resp = $providers->add(17801048874, 5, 10, ['order_sn' => $this->make_sn()]);
- $resp = $providers->query(['order_sn' => '930668700375312006']);
- // $str = 'amount=10.00&orderId=720668384771999671&phone=13911129867&payTime=2021-03-06+22%3A26%3A12&sign=94dfe83221f7768650e70cce08879b60&appKey=uECmTOFAY6RPCTtI&payUrl=&statusDes=%E6%94%AF%E4%BB%98%E5%A4%B1%E8%B4%A5&status=7';
- // $input = $this->parse_request($str);
- // $input['amount'] = 10.00;
- // $input['orderId'] = '92391614943913061206';
- // $input['phone'] = 17801048874;
- // $input['payTime'] = '2021-03-05 19:31:55';
- // $input['sign'] = 'bef6ae50319fb1e8cb3f21302f0abef8';
- // $input['appKey'] = 'uECmTOFAY6RPCTtI';
- // $input['payUrl'] = '';
- // $input['statusDes'] = '支付失败';
- // $input['status'] = 7;
- // refill\RefillFactory::instance()->notify('baizeyd',$input);
- }
- private function parse_request($squery)
- {
- if(empty($squery)) return [];
- $result = [];
- $params = preg_split('/&/', $squery);
- foreach ($params as $pair)
- {
- if(empty($pair)) continue;
- $kv = explode('=', $pair);
- $count = count($kv);
- if($count === 1) {
- $key = $kv[0];
- $val = "";
- }
- elseif($count === 2) {
- $key = $kv[0];
- $val = urldecode($kv[1]);
- }
- else {
- continue;
- }
- if(!empty($key)) {
- $result[$key] = $val;
- }
- }
- return $result;
- }
- public function testAmPhone()
- {
- // $providers = new refill\aming\RefillPhone([]);
- // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
- $input['result'] = 'fail';
- $input['msg'] = 0;
- $input['order'] = 'null';
- $input['phone_no'] = 18500608333;
- $input['sign'] = 'c925ad19c63c3eb36ffc52d938e24604';
- $input['amount'] = '10.00';
- $input['op_no'] = '42601615096072517841';
- refill\RefillFactory::instance()->notify('aming',$input);
- }
- public function testBhcPhone()
- {
- $providers = new refill\binghc\RefillPhone([]);
- $resp = $providers->query(['order_sn' => 250668618955902006]);
- // $input['result'] = 'fail';
- // $input['msg'] = 0;
- // $input['order'] = 'null';
- // $input['phone_no'] = 18500608333;
- // $input['sign'] = 'c3aa38ee07cd1b69bfd5ead56f6da8d6';
- // $input['amount'] = '10.00';
- // $input['op_no'] = '24061615096361999002';
- // refill\RefillFactory::instance()->notify('binghc',$input);
- }
- public function testRuishunPhone()
- {
- // $providers = new refill\ruishun\RefillPhone([]);
- // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
- $input['result'] = 'fail';
- $input['msg'] = 0;
- $input['order'] = null;
- $input['phone_no'] = 18500608333;
- $input['sign'] = 'e234f7d1c0458ca236f53a0008436b46';
- $input['amount'] = "10.00";
- $input['op_no'] = '76361615095403188513';
- refill\RefillFactory::instance()->notify('ruishun',$input);
- }
- public function testWuchenPhone()
- {
- $providers = new refill\wuchen\RefillPhone([]);
- // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
- $resp = $providers->query(['order_sn' => '790668630498425006']);
- // $input['app_id'] = '70016';
- // $input['message'] = 'fail';
- // $input['order_sn'] = '43101615277293035501';
- // $input['platform_order_id'] = '';
- // $input['sign'] = '5ea59f8ac51a518f2c622824d7db2a04';
- // $input['state'] = "fail";
- // $input['sys_sn'] = '202103091608231836913889';
- // $input['timestamp'] = '1615277361';
- // refill\RefillFactory::instance()->notify('wuchen',$input);
- }
- public function testYibaoPhone()
- {
- $providers = new refill\yibao\RefillPhone([]);
- $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
- // $resp = $providers->query(['order_sn' => '790668630498425006']);
- }
- public function testWeisPhone()
- {
- $providers = new refill\weisyd\RefillPhone([]);
- $resp = $providers->add(17801048874, 4, 10, ['order_sn' => $this->make_sn()]);
- }
- public function testXcPhone()
- {
- $providers = new refill\xc\RefillPhone([]);
- $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
- }
- public function testAfandPhone()
- {
- $providers = new refill\afand\RefillPhone([]);
- for ($i = 3; $i > 0; --$i) {
- $resp = $providers->add(18518267398, 4, 30, ['order_sn' => $this->make_sn()]);
- }
- }
- public function testAfandengPhone()
- {
- $providers = new refill\afandeng\RefillPhone([]);
- $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
- }
- public function testYifaPhone()
- {
- $providers = new refill\yifa\RefillPhone([]);
- $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
- }
- public function testTianjtOil()
- {
- $cardno = 1000111100021211884;
- $providers = new refill\tianjt\RefillOil([]);
- $resp = $providers->add($cardno, 2, 500, ['order_sn' => $this->make_sn()]);
- }
- public function testTianxPhone()
- {
- $cardno = 13699279618;
- $providers = new refill\tianx\RefillPhone([]);
- $resp = $providers->add($cardno, 4, 50, ['order_sn' => $this->make_sn()]);
- }
- public function testWeitPhone()
- {
- $providers = new refill\weit\RefillPhone([]);
- for ($i = 0;$i<=10;$i++){
- $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
- }
- }
- public function testWeitCB()
- {
- $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
- $params['status'] = 0;
- $params['price'] = 30;
- $params['op_order_id'] = '';
- $params['mch_order_id'] = '900664281823957221';
- $params['pt_order_id'] = '2021011802434412825405218901';
- $params['pay_type'] = '';
- $params['tel'] = 18500608333;
- $params['mchid'] = 10014;
- $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params , 'POST');
- }
- public function testYifaCB()
- {
- $body = '{"app_id":"e4a61b2acf1119c72c1ed9b61781494e","nonce_str":"OQMEBRQWJGPKOWYUXDVPTNMLEQJHXFWG","timestamp":1610275083,"order_sn":"161027325773032634","coder_order_sn":"60641610273255214687","isp_order_sn":null,"phone":"15120035568","amount":"94.000","discount":"0.9400","create_time":"2021-01-10 18:07:42","recharge_time":"","status":"fail","channel_id":3,"sign":"47278AD74EFA7F5FC8DE3A6D362C409B"}';
- $input = json_decode($body,true);
- refill\RefillFactory::instance()->notify('yifa',$input);
- }
- public function testBjbQuery()
- {
- $providers = new refill\bjb\RefillPhone([]);
- $refill_info = ['order_sn' => 110667993758599771, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
- $resp = $providers->query($refill_info);
- }
- public function testXcQuery()
- {
- $providers = new refill\xc\RefillPhone([]);
- $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
- $resp = $providers->query($refill_info);
- }
- public function testTianjtQuery()
- {
- $providers = new refill\tianjt\RefillOil([]);
- $refill_info = ['order_sn' => 680665862267622221, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
- $resp = $providers->query($refill_info);
- }
- public function testSaihuOil()
- {
- $providers = new refill\saihu\RefillOil([]);
- $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
- }
- public function testBdtOil()
- {
- $providers = new refill\bdt\RefillOil([]);
- $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
- }
- public function testGFTDOil()
- {
- $providers = new refill\gftd\RefillOil([]);
- $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
- }
- public function testGFTDCB()
- {
- $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
- $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
- $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;']);
- }
- public function testJiecPhone()
- {
- $providers = new refill\jiec\RefillPhone([]);
- $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
- }
- public function testBxtwtCB()
- {
- $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
- }
- public function testTianjtJDVerify()
- {
- $data = 'onlystr=920661883198026632&sign=533151e3f0dff5f507786aabc37b18f7&amt=100¬ifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php&jdno&cardtype=Sinoepc&batchid=26106&cardno=1000111100020654226&orgid=1590993600&status=3';
- $url = "http://192.168.1.220/mobile/refill_tianjt.php?" . $data;
- $resp = http_request($url);
- }
- public function testSuhcPDD()
- {
- $data = 'onlystr=820663525320005221&pddno&sign=4b1e8645f7541ced34855779448d9d52&amt=100¬ifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhcpdd.php&cardtype=Sinoepc&batchid=3&cardno=1000111100020445281&orgid=1590993600&status=2';
- $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
- $resp = http_request($url);
- }
- public function testSuhcTMVerify()
- {
- $data = 'onlystr=180662473867058221&sign=5ff5f95d54a89e78dbb49923f6b20c08&amt=100¬ifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhctm.php&cardtype=Sinoepc&batchid=3&cardno=1000111100020445281&orgid=1590993600&status=3';
- $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
- $resp = http_request($url);
- }
- public function testBeixtVerify()
- {
- $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
- $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
- $headers = ['Content-Type: application/json'];
- $resp = http_post_data($url, $data, $headers);
- }
- public function testInput()
- {
- $input = fopen("php://input", "rw");
- file_put_contents($input, 'xxxx');
- $content = file_get_contents('php://input');
- }
- 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' => $this->mMchid,
- 'cardno' => '1000111100020445281',
- 'amount' => "100",
- "act" => "refill",
- "op" => "add",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => $notifyurl];
- $resp = $this->send_md5($url, $params);
- Log::record($resp, Log::DEBUG);
- }
- public function testBalance()
- {
- $url = $this->mReqHost . "/mobile/index.php";
- $params = ['mchid' => 1092,
- "act" => "refill",
- "op" => "balance"];
- $resp = $this->send_md5($url, $params);
- Log::record($resp, Log::DEBUG);
- }
- public function testAddPhoe()
- {
- $phones = [//13911129867,
- 18500608333,
- 18510683168,
- 18513846008,
- 18518237398];
- $amount = 10;
- for ($i = 0; $i < 3; $i++) {
- foreach ($phones as $phone) {
- $url = $this->mReqHost . "/mobile/index.php";
- $params = ['mchid' => 1092,
- 'cardno' => $phone,
- 'amount' => $amount,
- "act" => "refill",
- "op" => "add",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
- $resp = $this->send_md5($url, $params);
- Log::record($resp, Log::DEBUG);
- }
- }
- }
- public function testProxyHelper()
- {
- $phone = '13911129867';
- $amount = 100;
- $url = $this->mReqHost . "/mobile/index.php";
- $params = ['mchid' => 1090,
- 'cardno' => $phone,
- 'amount' => $amount,
- "act" => "refill",
- "op" => "add",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => "https://xxx"];
- $proxy = new refill_proxy("xxx");
- $resp = $proxy->send($url, $params);
- }
- public function testGoods()
- {
- $req_url = $this->mReqHost . '/mobile/index.php';
- $params = ['mchid' => $this->mMchid,
- "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 testTianjtCB()
- {
- // $notifyurl = BASE_SITE_URL . "/mobile/refill_tianjt.php";
- $notifyurl = "https://www.xyzshops.cn/mobile/refill_tianjt.php";
- // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php";
- $params = ['onlystr' => '690665858589475818',
- 'amt' => 1000,
- 'jdno' => '',
- 'notifyurl' => $notifyurl,
- 'cardtype' => 'Sinoepc',
- 'batchid' => 30589,
- 'cardno' => '1000113300007993287',
- 'orgid' => '1590993600',
- 'status' => 3];
- $sign = $this->md5_sign($params);
- $params['sign'] = $sign;
- $resp = http_request($notifyurl, $params, 'POST');
- Log::record($resp, Log::DEBUG);
- }
- public function testBJBCB()
- {
- $params = [
- 'usr' => '13699279618',
- 'ord' => '710662733975412771',
- 'state' => '2',
- 'bz' => '',
- 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
- ];
- $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
- }
- public function testJiecCB()
- {
- $params['result'] = 'fail';
- $params['msg'] = '0';
- $params['order'] = 'null';
- $params['phone_no'] = '18500608333';
- $params['amount'] = '30.00';
- $params['op_no'] = '800663597981819221';
- $params['sign'] = '2510046895e8e12322c8a32547905ee9';
- $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
- }
- public function testZFKJ()
- {
- //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
- //&amount=10&order_sn=PH2012261356569433&
- //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
- //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
- $params = ['mchid' => 1090,
- 'cardno' => '100112121212212133',
- 'amount' => '10',
- "act" => "refill",
- "op" => "add",
- 'order_sn' => 'PH2012261356569433',
- 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
- $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
- }
- 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' => 18171,'manual' => true]);
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
- 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={$this->mKey}";
- $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);
- $body = "";
- $i = 0;
- foreach ($params as $k => $v) {
- if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
- if ($i == 0) {
- $body .= "{$k}" . "=" . urlencode($v);
- } else {
- $body .= "&" . "{$k}" . "=" . urlencode($v);
- }
- $i++;
- }
- }
- return $body;
- }
- 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 "<br>";
- }
- }
- public function testip()
- {
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
- $ipwhitelist = unserialize($merchant_info['ip_white_list']);
- $res = json_encode($ipwhitelist);
- }
- //测试向内部店提交订单,可先屏蔽其它充值通道
- public function testAddoilToInnerStore()
- {
- $url = $this->mReqHost . "/mobile/index.php";
- $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
- $params = ['mchid' => 1,
- 'cardno' => '1000111100020445281',
- 'amount' => "1000",
- "act" => "refill",
- "op" => "add",
- 'card_name' => '江海苗',
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => $notifyurl];
- $resp = $this->send_md5($url, $params);
- Log::record($resp, Log::DEBUG);
- }
- public function testRefillInnerCB()
- {
- $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
- $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
- }
- public function testArgs()
- {
- Log::record($_SERVER['argv'], Log::DEBUG);
- }
- public function testCall()
- {
- $order_id = 14974;
- QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true], 10);
- }
- public function testSyncconfig()
- {
- $name_val_cfg = function ($items) {
- $result = [];
- foreach ($items as $item) {
- $name = $item->name();
- $result[$name] = $item;
- }
- return $result;
- };
- $name_val_row = function ($items) {
- $result = [];
- foreach ($items as $item) {
- $name = $item['name'];
- $result[$name] = $item;
- }
- return $result;
- };
- $match = function ($all,$cur)
- {
- $insert = [];
- foreach ($all as $key => $value)
- {
- if(!array_key_exists($key,$cur)) {
- $insert[] = $key;
- }
- }
- return $insert;
- };
- $inserter = function ($mod,$type,$names)
- {
- foreach ($names as $name) {
- $data = ['name' => $name,'type' => $type];
- $mod->insert($data);
- }
- };
- $providers = refill\RefillFactory::instance()->providers();
- $oils = $name_val_cfg($providers['oil']);
- $phones = $name_val_cfg($providers['phone']);
- $mod_prov = Model('refill_provider');
- $oil_items = $mod_prov->getProviderList(['type' => 1]);
- $oil_items = $name_val_row($oil_items);
- $oil_inserts = $match($oils,$oil_items);
- $phone_items = $mod_prov->getProviderList(['type' => 2]);
- $phone_items = $name_val_row($phone_items);
- $phone_inserts = $match($phones,$phone_items);
- $inserter($mod_prov,1,$oil_inserts);
- $inserter($mod_prov,2,$phone_inserts);
- }
- public function testStat()
- {
- $model_refill_order = Model('refill_order');
- $stat = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
- ->where([])->select();
- }
- public function testRefillGoods()
- {
- $goods = refill\RefillFactory::instance()->goods();
- }
- private function make_mobile()
- {
- $no = "1" . mt_rand(3000000000, 3999999999);
- return $no;
- }
- private function refill_info($card_no, $card_type)
- {
- $data = rcache($card_no, 'cardrefill-');
- if(empty($data))
- {
- $mod_topcard = Model('topcard');
- $ret = $mod_topcard->get_card($card_no);
- if(empty($ret)) {
- $bind_phone = $this->make_mobile();
- $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
- $data['bind_phone'] = $bind_phone;
- $data['refill_time'] = time();
- $data['times'] = 0;
- wcache($card_no,$data,'cardrefill-');
- }
- else {
- $val = $ret[0];
- $data['bind_phone'] = $val['bind_phone'];
- $data['refill_time'] = time();
- $data['times'] = 0;
- }
- }
- return $data;
- }
- public function testGetMobile()
- {
- $card_no = '1000119000001679247';
- $card_type = 1;
- $info = $this->refill_info($card_no,$card_type);
- }
- private function check_mchorder($mchid,$mch_order)
- {
- if(empty($mch_order)) {
- return true;
- }
- else {
- $refill_order = Model('refill_order');
- $ret = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
- return empty($ret);
- }
- }
- public function testCheckMchorder()
- {
- $ret = $this->check_mchorder(1,'13281475');
- }
- public function testMakemobile()
- {
- $mobile = refill\util::make_mobile();
- $ret = refill\util::set_black('1000111100020445281');
- }
- public function testLoadBlack()
- {
- $path = BASE_DATA_PATH . "/log";
- $names = ['20210119-mobile.log',
- '20210120-mobile.log','20210121-mobile.log','20210122-mobile.log','20210123-mobile.log',
- '20210124-mobile.log','20210125-mobile.log'];
- foreach ($names as $name)
- {
- $file_name = $path . "/" . $name;
- refill\util::black_from_log($file_name);
- }
- }
- public function testStats()
- {
- $date = date('Y-m-d',time());
- $today = strtotime("{$date}");
- $times_begin = function ($start) {
- $times = [];
- $begin = $start;
- for($i = 0; $i < 7; $i++) {
- $times[] = $begin;
- $begin -= 86400;
- }
- return $times;
- };
- $reader = function ($mchid,$time) {
- $cond['mchid'] = $mchid;
- $cond['inner_status'] = 0;
- $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 -1]];
- $items = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
- ->group('vr_order.order_state')
- ->where($cond)->select();
- return $items;
- };
- $begins = $times_begin($today);
- $mchid = 10096;
- // $states = rcache($this->mchid() , 'refillstat-');
- $states = unserialize($states ?? "");
- if(empty($states)) $states = [];
- $result = [];
- $cache = [];
- foreach ($begins as $begin)
- {
- if(array_key_exists($begin,$states)) {
- $item = $states[$begin];
- }
- else {
- $item = $reader($mchid,$begin);
- }
- $result[$begin] = $item;
- //判断item 中充值中的状态是否为0,为0的情况下放进cache
- $cache = $item;
- }
- wcache($this->mchid() ,$cache, 'refillstat-');
- return $result;
- }
- public function testNotifyx()
- {
- $mch_cache = rcache("merchant-notify" , 'refill-');
- $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
- $new_caches = [];
- $merchants = Model('merchant')->getMerchantList([],'','','merchant.*,member.available_predeposit' ,"0,1000");
- foreach ($merchants as $merchant)
- {
- $mchid = $merchant['mchid'];
- $phone = $merchant['contact_phone'] ?? "";
- $available_pd = intval($merchant['available_predeposit']);
- $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
- if(array_key_exists($mchid,$caches)) {
- $mch_cache = $caches[$mchid];
- }
- else {
- $mch_cache = ['last_time' => 0, 'send_count' => 0];
- }
- if(!empty($phone) && ($available_pd < $alarm_pd))
- {
- $counts = $mch_cache['send_count'];
- if(($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
- $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
- QueueClient::push('sendSMS', ['mobile'=>$merchant['contact_phone'],
- 'type'=>'balance_warning','datas' => [date("m月d日H时") , $merchant['available_predeposit']]]);
- }
- }
- else {
- $mch_cache = ['last_time' => 0, 'send_count' => 0];
- }
- $new_caches[$mchid] = $mch_cache;
- }
- wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
- }
- public function testReadChannel()
- {
- refill\RefillFactory::instance()->read_channel();
- }
- public function testAllow()
- {
- $allow = refill\RefillFactory::instance()->allow(10096,1,100);
- }
- public function testCheckData(){
- $str = '|2|110667993758599771-充值失败|';
- // $str = '0|提交成功|-36557.7400';
- // if(preg_match( '/^-*[0-9]{1,3}\|[\x{4e00}-\x{9fa5}]+\|-*[0-9]+\.*[0-9]+$/u',$str,$matches)) {
- // return true;
- // }
- // if(preg_match('/^[0-3]\|[0-9]+-*[\x{4e00}-\x{9fa5}]+\|[0-9]*$/u',$str,$matches)){
- // return true;
- // }
- // return false;
- $resp = ltrim($str , '|');
- $resp = explode('|' , $resp);
- if(count($resp) != 3) {
- return [false,'返回值错误'];
- }
- }
- public function testErrre()
- {
- $line = '[13 2021-01-24 16:07:03] DEBUG: type = application/json;charset=utf-8, content={"channelOrderNumber":"610664819621371793","orderNumber":"GYFL1611475621525437","message":"充值失败","signature":"6c28c15b9ce2b2243742ecebbd929ac5","status":109}';
- $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u',$line,$matches);
- }
- public function testLog()
- {
- // $line = './LOG/20210203-mobile.log:[15 2021-02-03 10:41:17] SQL: UPDATE `lrlz_member` SET available_predeposit=available_predeposit+975 WHERE ( member_id = \'65818\' ) [ RunTime:0.000297s ]';
- $fn = fopen(BASE_ROOT_PATH . "/10096.log","r");
- $mod = Model();
- $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>0]);
- $total_amount = ncPriceFormat(0.00);
- $i = 0;
- while(! feof($fn)) {
- $i++;
- $line = trim(fgets($fn));
- $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i',$line,$matches);
- if($ret) {
- $oper = $matches['oper'];
- $amount = $matches['amount'];
- if($oper == '-') {
- $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
- // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
- }
- else {
- $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
- // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
- }
- Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}",Log::DEBUG);
- }
- }
- Log::record("total_amount:{$total_amount}",Log::DEBUG);
- fclose($fn);
- }
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
- //docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
|