zop_key = [ 'appCode' => '', 'HMACMD5' => '', 'AES' => '' ]; $this->referrerCode = [ '南京' => '3415708788', '扬州' => '3415711261', '连云' => '3415708759', '盐城' => '3415708910', '淮安' => '3415711466', '镇江' => '3415711154', '宿迁' => '3415711567', '无锡' => '3415708835', '泰州' => '3415711151', '南通' => '3415708883', '苏州' => '3415710870', '徐州' => '3415710721', '常州' => '3415710817', ]; $this->channel = [ '江苏' => '09-2279-bn66-9999', ]; $this->channelCode = "09-2279-bn66-9999"; } public function valid($order, $packageBind = NULL) { return array('code' => 1, 'msg' => '校验通过'); } /** * @inheritDoc 同步 */ public function send($order, $packageBind = NULL) { // TODO: Implement send() method. if (empty($order->iden_card_name) || empty($order->iden_card_id)) return array('code' => 0, 'msg' => '身份证姓名或号码为空'); // $salesId = $this->getSalesId($order, $packageBind); // if (empty($salesId)) { // Log::error('订单校验 : 未绑定套餐 .' . $order->order_no); // return array('code' => 0, 'msg' => '未绑定套餐,销售品编码为空sxlt2'); // } $salesId = $order->out_package_id; //地址及编码解析 //地址参数:province,city,area,details_address,format_address //编码参数:p_code,c_code,a_code $addinfo = new GetAddressInfo(); $add2code = new Add2Code(); $add_data = $addinfo->getAddInfo($order->express_address); $province = $add_data['province']; $city = $add_data['city']; $area = $add_data['area']; $format_address = $add_data['format_address']; if($province != '江苏省') return ['code' => 0, 'msg' => '省外不发']; $code_data = $add2code->get_codeInfo($add_data, 'Shanxikuandai_code'); $p_code = $code_data['p_code']; $c_code = $code_data['c_code']; $a_code = $code_data['a_code']; if(empty($p_code) or empty($c_code) or empty($a_code)) return array('code' => 0, 'msg' => "地区编码解析失败,$province--$city--$area".'--'.$p_code.'--'.$c_code.'--'.$a_code); //产品拼接过 这里要进行处理 $salesIdArr = explode('&',$salesId); if(empty($salesIdArr[0]) || empty($salesIdArr[1]) || empty($salesIdArr[2])) return ['code' => 0, 'msg' => '产品配置错误']; $prodGuishu = $salesIdArr[0];//发省内还是发全国 $prodId = $salesIdArr[1];//产品编码 $prodName = $salesIdArr[2];//产品名称 $price = $salesIdArr[3] - 100;//价格 // $channel = $salesIdArr[3];//触点编码 // $developerId = $salesIdArr[4];//发展人编码 // L计划&000000000000&480元包年300m宽带(省集中处理)&08-2278-3840-bkvc&1714833893 // $channel = $this->channel[substr($city,0,6)]; $channel = $this->channelCode; $developerId = $this->referrerCode[substr($city,0,6)]; // NEWACCESSWAY $url = 'http://e.com/zop/link/boradband/actPreOrder/submit/v1'; $body = [ "channel" => $channel, //触点编码 "sceneTag" => "NEWACCESSWAY",//活动场景 "tId" => trim($order->order_no),//合作方订单号 // "activeId" => "xxxx",//活动ID【重要】需确保活动id的有效性,如果由于活动id传值不正确导致发券问题需责任自负。 // "activeName" =>"xxxx",//活动名称 "goodsId" => $prodId,//商品ID "goodsName" => $prodName,//商品名称(奖品名称) 命名规范:装宽带意向单-XXXX "processDiff" => "JSHKZJ", "developerId" => $developerId, "referrerCode" => $developerId, "remarks" => "套餐费".$price."元,调测费0元,未支付JSHKZJ".trim($order->order_no),//备注 // "appointmentTime" => "2022-04-27 10:04:24",//预约安装时间 YYYY-MM-DD HH24:mi:ss "custInstallData" => [//用户信息 "psptTypeCode" => "02",//证件类型 02 身份证 "psptNo" => trim($order->iden_card_id),//证件号码 "custName" => trim($order->iden_card_name),//客户名称 "contactPhone" => trim($order->mobile),//联系人电话/客户号码 "provinceCode" => $p_code,//省份编码 "cityCode" => $c_code,//地市编码 "districtCode" => $a_code,//区县编码 "custInstallAddr" => $format_address//详细地址 ] ]; $reqParam = $this->jiami($body); echo json_encode($body,JSON_UNESCAPED_UNICODE); echo "\n"; // return; Log::info($order->order_no."江苏联通宽带提交:".json_encode($body,JSON_UNESCAPED_UNICODE)); $res = $this->req($url, $reqParam); // echo 222; echo json_encode($res,JSON_UNESCAPED_UNICODE); echo "\n"; // return; Log::info($order->order_no."江苏联通宽带返回:".json_encode($res,JSON_UNESCAPED_UNICODE)); // if(empty($res)) return array('code' => 2, 'msg' => '服务器未响应,请提交'); // //成功 if($res['rspCode'] == '0000'){ if(empty($res['body'])) return array('code' => 0, 'msg' => '失败,body不存在'); // $body = json_decode($res['body'],true); return array('code' => 1, 'msg' => '成功','api_order_no' => $res['body']['orderNo'],'intercept_msg' => $res['body']['orderId']); //失败 }else{ return array('code' => 0, 'msg' => $res['rspDesc']); } } //查询宽带是否竣工 public function orderCheck($order, $packageBind = NULL) { $apinotify = Apinotify::where('api_order_no', $order->api_order_no)->select(['up_status','active_message','api_order_no','order_id','order_no'])->first(); // echo json_encode($apinotify,JSON_UNESCAPED_UNICODE); // echo "\n"; if(!empty($apinotify)){ if($apinotify->up_status == 2){ $this->delMsg($apinotify->order_no); //删除消息 return [ 'code' => 1, 'active_message' => $apinotify->active_message, 'active_status' => 1, 'phonenum' => $apinotify->order_id ]; } } return; } //获取消息 public function getMsg() { // $apinotify = Apinotify::where('api_id', 123)->select(['up_status','active_message','api_order_no'])->get(); // echo json_encode($apinotify,JSON_UNESCAPED_UNICODE); // echo "\n"; // echo count($apinotify); // return; // $salesId = $this->getSalesId($order, $packageBind); // if (empty($salesId)) { // Log::error('订单校验 : 未绑定套餐 .' . $order->order_no); // return array('code' => 0, 'msg' => '未绑定套餐,销售品编码为空sxlt2'); // } // //产品拼接过 这里要进行处理 // $salesIdArr = explode('&',$salesId); // if(empty($salesIdArr[0]) || empty($salesIdArr[1]) || empty($salesIdArr[2])) return ['code' => 0, 'msg' => '产品配置错误']; // $prodGuishu = $salesIdArr[0];//发省内还是发全国 // $prodId = $salesIdArr[1];//产品编码 // $prodName = $salesIdArr[2];//产品名称 // $channel = $salesIdArr[3];//触点编码 $channel = $this->channelCode; $url = 'http://e.com/zop/link/king/broad/getMsg'; $body = [ // "mesChannel" => "sdhk", // "gridCode" => "01", "touchApplyId" => $channel, "type" => "4" ]; $reqParam = $this->jiami($body); // echo json_encode($body,JSON_UNESCAPED_UNICODE); // echo "\n"; // return; // $datw = "20240306 17:18:21"; // echo date("Y-m-d H:i:s",strtotime($datw)); Log::info("江苏联通宽带竣工消息提交:".json_encode($body,JSON_UNESCAPED_UNICODE)); $res = $this->req($url, $reqParam); if(empty($res)) return ["code" => 2, "msg" => "服务器未响应"]; // echo json_encode($res,JSON_UNESCAPED_UNICODE); Log::info("江苏联通宽带竣工消息返回:".json_encode($res,JSON_UNESCAPED_UNICODE)); if($res['rspCode'] == '0000'){ if(!empty($res['body'])){ foreach ($res['body'] as $value){ $resNotify = $this->notify($value); // if($resNotify['code'] == 1 && !empty($resNotify['msgId'])){ // $this->delMsg($resNotify['msgId']); // } } } return; }else{ return array('code' => 0, 'msg' => $res['rspDesc']); } } //获取消息 public function delMsg($msgId) { $url = 'http://e.com/zop/link/king/broad/delMsg'; $body = [ // "mesChannel" => "sdhk", // "gridCode" => "01", "msgId" => $msgId, "type" => "4" ]; $reqParam = $this->jiami($body); $res = $this->req($url, $reqParam); // echo json_encode($res,JSON_UNESCAPED_UNICODE); if($res['rspCode'] == '0000'){ return array('code' => 1, 'msg' => '删除成功'); }else{ return array('code' => 0, 'msg' => $res['rspDesc']); } } public function notify($data) { // 节点 父节点 类型 长度 约束 注释 // Id body string V20 1 消息ID // orderId body string V20 1 商城宽带订单号 // createTime body string V20 1 宽带竣工时间:yyyyMMdd HH24:mi:ss // touchApplyId body string V20 ? 下单触点编码(也就是下单链接里带的channel参数,如08-1234-5678-9999) // contactNumber body string V20 ? 联系电话 // broadBandNumber body string V20 ? 宽带号码 // $data = [ // "orderId" =>"556767610882", // "createTime" =>"20240306 12:23:33", // "touchApplyId" =>"07-4355-bdl8-9999", // "contactNumber" =>"13468929987", // "broadBandNumber" =>"02904681142", // "channel" =>null, // "value1" =>null, // "id" =>"7824030776196202" // ]; $status = 3; $open_message = null; $active_status = null; $activityTime = null; $time = date("Y-m-d H:i:s",time()); $order_id = empty($data['broadBandNumber']) ? '' : $data['broadBandNumber']; //宽带单号 $api_order_no = empty($data['orderId']) ? '' : $data['orderId']; //运营商单号 $order_no = empty($data['id']) ? '' : $data['id']; //消息id $touchApplyId = empty($data['touchApplyId']) ? '' : $data['touchApplyId']; //下单触点编码 //竣工时间 if(!empty($data['createTime'])){ $activityTime = date("Y-m-d H:i:s",strtotime($data['createTime'])); $status = 2; $open_message = '已竣工'; //开卡回文 $active_status = 1; } $apinotify = Apinotify::where('api_order_no', $api_order_no)->first(); // return $apinotify; if(empty($apinotify)){ $data = [ 'name' => "江苏联通宽带", 'api_order_no' => $api_order_no, 'order_no' => $order_no, 'order_id' => $order_id, // 'phone' => $mobile, // 'express_no' => $logisticsNo, 'express_name' => $touchApplyId, // 'open_status' => "", // 'status_time' => $activityTime, 'created_at' => $time, 'updated_at' => $time, 'api_id' => "158", // 'first_charge_status' => "", // 'first_charge_time' => "", 'up_status' => $status, 'active_message' => $activityTime, 'active_status' => $active_status, //已激活 'open_message' => $open_message, ]; $res = Apinotify::insert($data); if ($res == 1) { return array('code' => 1, 'success' => 'true', 'msgId' => $order_no); } else { return array('code' => 0, 'success' => 'false'); } }else{ $data = [ 'api_order_no' => $api_order_no, 'order_no' => $order_no, 'order_id' => $order_id, 'updated_at' => $time, // 'phone' => $mobile, 'up_status' => $status, 'active_message' => $activityTime, 'active_status' => $active_status, //已激活 'open_message' => $open_message, ]; $apinotify->update($data); return array('code' => 1, 'success' => 'true', 'msgId' => $order_no); } return array('code' => 0, 'success' => 'false'); } /** * @inheritDoc 参数加密 */ public function jiami($body) { // TODO: Implement send() method. // uuid $uuid = $this->uuid(); // 生成时间戳 $timestamp = $this->getTimestamp(); $head = [ 'sign' => $this->genSign($uuid, $timestamp), 'timestamp' => $timestamp, 'uuid' => $uuid ]; $reqObj = [ 'head' => $head, 'body' => $body ]; $reqObj = $this->encrypt(json_encode($reqObj),$this->zop_key['AES']); $reqParam = [ 'appCode' => $this->zop_key['appCode'], 'reqObj' => $reqObj ]; return $reqParam; } //图片转base64位 function base64EncodeImage($ImageFile) { $base64_image = ''; $image_data = @file_get_contents($ImageFile); if(!$image_data){ return false; } $base64_image = chunk_split(base64_encode($image_data)); return $base64_image; } function req($url, $post_data) { $opt_data = json_encode($post_data); $header = array(); $header[] = 'Accept:application/json'; $header[] = 'Content-Type:application/json;charset=utf-8'; $curl = curl_init(); //初始化 curl_setopt($curl, CURLOPT_URL, $url); //设置url curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POSTFIELDS, $opt_data); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_POST,1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 不验证SSL curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 不验证SSL $result = curl_exec($curl); $headerSize = curl_getinfo($curl); // return $headerSize; if($result === false){ echo curl_errno($curl); exit(); } curl_close($curl); // return $result; return json_decode($result,true); } /** * uuid 唯一序列码 * @param string $prefix * @return string */ function uuid($prefix = '') { $chars = md5(uniqid(mt_rand(), true)); $uuid = substr($chars, 0, 8) . '-'; $uuid .= substr($chars, 8, 4) . '-'; $uuid .= substr($chars, 12, 4) . '-'; $uuid .= substr($chars, 16, 4) . '-'; $uuid .= substr($chars, 20, 12); return $prefix . $uuid; } //获取当前时间毫秒 function msectime() { list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectime; } // 时间戳 function getTimestamp() { date_default_timezone_set('PRC'); $time = $this->msectime(); return date('Y-m-d H:i:s.') . substr($time, -3); } // 生成签名 function genSign($uuid, $timestamp) { $dataStr = 'appCode' .$this->zop_key['appCode'] . 'timestamp' . $timestamp . 'uuid' . $uuid . $this->zop_key['HMACMD5']; return $this->sign($this->zop_key['HMACMD5'], $dataStr); } /** * 签名 * @param key 密钥 联通侧提供的HmacMD5 * @param dataStr appCode+appCode值+timestamp+timestamp值*+uuid+uuid值+HmacMD5密钥值 */ function sign($key, $dataStr) { return base64_encode(hash_hmac("md5", $dataStr, base64_decode($key), true)); } /** *AES加密 */ function encrypt($data, $key) { $data = openssl_encrypt($data, 'aes-128-ecb', base64_decode($key), OPENSSL_RAW_DATA); return base64_encode($data); } //计算年龄 function getAge($id){ # 1.从身份证中获取出生日期 $id = $id;//身份证 $birth_Date = strtotime(substr($id, 6, 8));//截取日期并转为时间戳 # 2.格式化[出生日期] $Year = date('Y', $birth_Date);//yyyy $Month = date('m', $birth_Date);//mm $Day = date('d', $birth_Date);//dd # 3.格式化[当前日期] $current_Y = date('Y');//yyyy $current_M = date('m');//mm $current_D = date('d');//dd # 4.计算年龄() $age = $current_Y - $Year;//今年减去生日年 // if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日) // $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁 // } # 返回 return $age; } //订单编码 public function getSalesId($order, $packageBind): string { $salesId = "0"; foreach ($packageBind as $bind) { if ($bind['id'] == $order->package_id) { $salesId = $bind['title']; break; } } //判断是否是外部套餐 // if (empty($salesId)) { // $package = Package::find($order->package_id); // if (!empty($package)) { // if (!empty($package->package_id)) { // foreach ($packageBind as $bind) { // if ($bind['id'] == $package->package_id) { // $salesId = $bind['title']; // break; // } // } // } // } // } return $salesId; } }