123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace App\Http\Utils\TaoBao;
- use App\Exceptions\TaobaoException;
- use App\Http\Utils\BaseUtil;
- use ETaobao\Factory;
- /**
- * 淘宝联盟工具类
- * Class TaobaoLianMengUtil
- * @package App\Http\Utils\TaoBao
- */
- class TaobaoLianMengUtil extends BaseUtil
- {
- /**
- * 获取淘宝联盟实例对象
- * @return \ETaobao\Tbk\Application
- */
- public static function getApp()
- {
- $config = config("taobao");
- return Factory::tbk($config);
- }
- /**
- * 获取官方活动信息接口
- * @param $adzone_id string 推广位ID
- * @param $activity_material_id string 活动ID
- */
- public static function getActivityInfo($adzone_id,$activity_material_id)
- {
- $app = self::getApp();
- $params = [
- "adzone_id"=>$adzone_id,
- "activity_material_id"=>$activity_material_id
- ];
- $res = $app->content->getActivityInfo($params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["sub_msg"]);
- }
- return $res["data"];
- }
- /**
- * 获取私域用户邀请码
- * @param $codeType int 邀请码类型,1 - 渠道邀请,2 - 渠道裂变,3 -会员邀请
- * @param int $relationId 渠道关系ID
- */
- public static function getInviteCode($codeType, $relationId = 0)
- {
- $app = self::getApp();
- $params = [
- "relation_app"=>"common",
- "code_type"=>$codeType
- ];
- if($relationId){
- $params["relation_id"] = $relationId;
- }
-
- $res = $app->sc->getInviteCode($params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["msg"]);
- }
- return $res["data"];
- }
- /**
- * 渠道备案
- * @param $inviteCode string 邀请码
- * @param $infoType int 类型,必选 默认为1:
- */
- public static function savePublisherInfo($inviteCode, $infoType)
- {
- $app = self::getApp();
- $params = [
- "inviter_code"=>$inviteCode,
- "info_type"=>$infoType
- ];
- $res = $app->sc->savePublisherInfo($params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["sub_msg"]);
- }
- return $res["data"];
- }
- /**
- * 获取备案信息
- * @param $infoType int 类型,必选 1:渠道信息;2:会员信息
- * @param $id string 渠道或者会员ID
- * @param string $relationApp 默认common
- */
- public static function getPublisherInfo($infoType,$id,$relationApp="common")
- {
- $app = self::getApp();
- $params = [
- "info_type"=>$infoType,
- "relation_app"=>$relationApp
- ];
- switch ($infoType){
- case 1:
- $params["relation_id"] = $id;
- break;
- case 2:
- $params["special_id"] = $id;
- break;
- }
- $res = $app->sc->getPublisherInfo($params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["sub_msg"]);
- }
- return $res["data"];
- }
- /**
- * 获取拉新用户订单
- * @param $activityId string 活动ID
- * @param int $page int 第几页
- */
- public static function getNewOrder($activityId, $page = 1)
- {
- $app = self::getApp();
- $params = [
- "page_no"=>$page,
- "activity_id"=>$activityId
- ];
- $res = $app->dg->getOrderNewUser($params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["sub_msg"]);
- }
- return $res["results"];
- }
- /**
- * 获取淘口令接口
- * @param $url string 地址
- */
- public static function taokoulingCreate($url)
- {
- $app = self::getApp();
- $params = [
- "url"=>$url
- ];
- $res = $app->tpwd->create($params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["sub_msg"]);
- }
- return $res["data"];
- }
- /**
- * 淘口令解析&转链
- * @param $kouling 淘口令
- */
- public static function taokoulingConvert($kouling)
- {
- $app = self::getApp();
- $params = [
- "password_content"=>$kouling,
- "adzone_id"=>"70362850341"
- ];
- $res = $app->tpwd->httpPost("taobao.tbk.tpwd.convert",$params);
- $res = json_decode(json_encode($res),true);
- if(isset($res["code"])){
- throw new TaobaoException($res["sub_msg"]);
- }
- return $res["data"];
- }
- /**
- * 获取饿了么外卖推广链接
- * @param $userId string 用户ID
- * @param $actId string 活动ID
- * @param string $linkType string 类型
- * @param string $spreadId 推广位
- */
- public static function getElmWaimaiSpreadUrl($userId, $actId, $linkType="mini",$spreadId = "111538400047")
- {
- $key = "elmUrl:".$userId."linktype:".$linkType."actid:".$actId;
- //判断缓存中是否存在
- $val = self::getCacheFromRedis($key);
- if($val){
- return $val;
- }
- //不存在则从官方获取
- $res = self::getActivityInfo($spreadId,$actId);
- switch ($linkType){
- case "h5":
- //h5链接
- $val = $res["short_click_url"];
- break;
- case "mini":
- //小程序
- $val = $res["wx_miniprogram_path"];
- break;
- }
- self::setRedisCache($key,$val,0);
- return $val;
- }
- }
|