123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- /**
- * MobileRecharge.php UTF-8
- * 手机充值提现实现类
- *
- * @date : 2018/5/3 23:07
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huolib\withdraw\driver;
- use huolib\constant\SettleConst;
- use huolib\tool\Http;
- use huolib\withdraw\Driver;
- class MobileRecharge extends Driver {
- private $openId;
- private $appKey;
- private $telcheck = 'http://op.juhe.cn/ofpay/mobile/telcheck';/* 检测手机号码是否能充值 */
- private $onlineorder = 'http://op.juhe.cn/ofpay/mobile/onlineorder';/* 手机直充接口 */
- private $ordersta = 'http://op.juhe.cn/ofpay/mobile/ordersta';/* 订单状态查询 */
- private $mobile;
- private $money;
- /**
- * 构造函数
- *
- */
- public function __construct() {
- $_conf_file = GLOBAL_CONF_PATH.'extra/unionapi/ofpay/config.php';
- if (file_exists($_conf_file)) {
- $_config = include $_conf_file;
- } else {
- $_config = array();
- }
- $this->openId = $_config['openId'];
- $this->appKey = $_config['appKey'];
- }
- /**
- * 企业付款
- * https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
- *
- * @throws \WxPayException
- */
- public function withDraw() {
- $_params['phoneno'] = $this->mobile;
- $_params['cardnum'] = 1;
- $_params['orderid'] = $this->order_id;
- $_params['key'] = $this->appKey;
- /*校验值,md5(OpenID+key+phoneno+cardnum+orderid),OpenID在个人中心查询 */
- $_sign = $this->openId.$this->appKey.$_params['phoneno'].$_params['cardnum'].$_params['orderid'];
- $_params['sign'] = md5($_sign);
- $_result = Http::post($this->onlineorder, $_params);
- $_re_data['result'] = $_result;
- if (!empty($_result)) {
- $_result = json_decode($_result, true);
- $_re_data['code'] = $_result['error_code'];
- $_re_data['msg'] = $_result['reason'];
- if ($_result['error_code'] == 0) {
- $_re_data['code'] = SettleConst::SETTLE_SUCCESS;
- } else if ($_result['error_code'] == 10014) { //订单异常,需求查询结果
- $_query_result = $this->orderQuery($this->order_id);
- $_re_data['code'] = $_query_result['code'];
- $_re_data['query_result'] = $_query_result['query_result'];
- }
- } else { //网络异常,需求查询结果
- $_query_result = $this->orderQuery($this->order_id);
- $_re_data['code'] = $_query_result['code'];
- $_re_data['query_result'] = $_query_result['query_result'];
- }
- return $_re_data;
- }
- /**
- * 查询手机号码是否可以充值
- *
- * @param $mobile 手机号
- * @param $money 充值金额,目前可选:1、2、5、10、20、30、50、100、200、300、500
- */
- private function telcheck($mobile, $money) {
- $_params['phoneno'] = $mobile;
- $_params['cardnum'] = $money;
- $_params['key'] = $this->appKey;
- $_result = Http::post($this->telcheck, $_params);
- print_r($_result);
- exit;
- }
- /**
- * 根据订单号查询状态
- *
- * @param $orderid 订单id
- *
- * @return mixed
- */
- public function orderQuery($orderid, $ext = null) {
- $_params['orderid'] = $orderid;
- $_params['key'] = $this->appKey;
- $_result = Http::post($this->ordersta, $_params);
- $_re_data['code'] = '';
- $_re_data['query_result'] = $_result;
- if (empty($_result)) {
- return $_re_data;
- }
- $_result = json_decode($_result, true);
- $_re_data['code'] = $_result['error_code'];
- if ($_result['error_code'] != 0) {
- return $_re_data;
- } else if ($_result['result']['game_state'] != 9) {
- /*状态 1:成功 9:失败 0:充值中*/
- $_re_data['code'] = SettleConst::SETTLE_SUCCESS;
- return $_re_data;
- } else {
- return $_re_data;
- }
- }
- /**
- * @return mixed
- */
- public function getMoney() {
- return $this->money;
- }
- /**
- * @param mixed $money
- */
- public function setMoney($money) {
- $this->money = $money;
- }
- /**
- * @return mixed
- */
- public function getMobile() {
- return $this->mobile;
- }
- /**
- * @param mixed $mobile
- */
- public function setMobile($mobile) {
- $this->mobile = $mobile;
- }
- }
|