123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?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');
- const LocalTest = 1;
- const NetTest = 2;
- const CurrentTest = LocalTest;
- class TestRefill extends TestCase
- {
- private $mReqHost = '';
- public function __construct(?string $name = null, array $data = [], $dataName = '')
- {
- parent::__construct($name, $data, $dataName);
- if(CurrentTest == LocalTest) {
- $this->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 "<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);
- }
- }
|