123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
- use PHPUnit\Framework\TestCase;
- 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');
- require_once(BASE_HELPER_PATH . '/refill/beixt/RefillCallBack.php');
- class TestRefill extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testFactory()
- {
- $providers = refill\RefillFactory::instance()->find_providers(100,mtopcard\SinopecCard);
- if(empty($providers)) return false;
- $input = [
- 'order_sn' => '200649600557717656',
- 'notifyurl' => "https://www.xyzshops.cn/mobile/signature.php"
- ];
- foreach ($providers as $provider) {
- $resp = $provider->add("1000111100021211884",mtopcard\SinopecCard,100,$input);
- }
- }
- public function testRefillPhone()
- {
- // $providers = new \refill\beixt\RefillPhone();
- // $resp = $providers->add(18500608333,50,'200649600557718888');
- //{"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'] = 13281474;
- $params['shipping_status'] = 1;
- $params['shipping_status_desc'] = '已发货';
- $params['shipping_status_message'] = '';
- $params['sign'] = '05863f9931ed69a70e456222f057dfdd';
- $params['voucher'] = '110103307162012081746340295254';
- $params['vouchertype'] = '';
- $params['voucherurl'] = '';
- $params['tradeNo'] = '200649600557718888';
- $ret = refill\RefillFactory::instance()->notify('beixt',$params);
- }
- public function testAddoil()
- {
- // $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,
- 'cardno' => '1000111100020445281',
- 'amount' => "100",
- "act"=>"refill",
- "op"=>"add",
- 'order_sn' => "13281476",
- 'notifyurl'=> $notifyurl];
- $resp = $this->send_md5($req_url,$params);
- }
- 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 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 testAddPhoe()
- {
- $params = ['mchid' => 10088,
- 'cardno' => '15120035568',
- 'amount' => "50",
- "act"=>"refill",
- "op"=>"add",
- 'order_sn' => "13281475",
- 'notifyurl'=> BASE_SITE_URL . "/mobile/beixt_notify.php"];
- $this->send($params);
- }
- 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 "<br>";
- }
- }
- 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);
- }
- }
|