find_oil(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":"未发货"}} // content={"order_number":13281474,"shipping_status":1,"shipping_status_desc":"已发货","shipping_status_message":"","sign":"05863f9931ed69a70e456222f057dfdd","voucher":"110103307162012081746340295254","vouchertype":"","voucherurl":"","tradeNo":"200649600557718888"} } public function testAddoil() { $params = ['mchid' => 1,'cardno' => '1000111100021211884','amount' => "100","act"=>"refill","op"=>"addoil", 'order_sn' => "13281474", 'notifyurl'=> BASE_SITE_URL . "/mobile/suhc_notify.php"]; $this->send($params); } public function testSuhcCB() { $notifyurl = BASE_SITE_URL . "/mobile/refill_suhc.php"; $params = ['onlystr' => '200660783085683671', 'amt' => 100, 'jdno'=>'', 'notifyurl' => $notifyurl, 'cardtype' => 'Sinoepc', 'batchid' => 15678, 'cardno' => '1000111100021211884', 'orgid' => '1590993600', 'status' => 2]; $sign = $this->md5_sign($params); $params['sign'] = $sign; $resp = http_request($notifyurl,$params,'POST'); Log::record($resp,Log::DEBUG); } private function md5_sign($params) { ksort($params); $body = ""; $i = 0; foreach ($params as $k => $v) { if ($i == 0) { $body .= "{$k}"; if(!empty($v)) { $body .= "=" . $v; } } else { $body .= "&" . "{$k}"; if(!empty($v)) { $body .= "=" . $v; } } $i++; } $body .= "&key=7yDCLS6S2KzSAJQOUc3vsa"; return md5($body); } public function testCallMech() { $logic = Logic('queue'); $logic->NotifyMerchantComplete(['order_id' => 289]); } private function send($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(BASE_SITE_URL . "/mobile/index.php",$params,'POST'); Log::record("resp:{$resp}",Log::DEBUG); } 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 "
"; } } }