| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.commons.httpclient.HttpClient;
|
| | | import org.apache.commons.httpclient.HttpException;
|
| | | import org.apache.commons.httpclient.NameValuePair;
|
| | | import org.apache.commons.httpclient.methods.PostMethod;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.share.PidUserMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TBPidMapper;
|
| | | import com.yeshi.fanli.entity.taobao.ClientTBPid;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TBPid;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.TBPidService;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class TBPidServiceImpl implements TBPidService {
|
| | |
|
| | | @Resource
|
| | | private TBPidMapper tbPidMapper;
|
| | |
|
| | | @Resource
|
| | | private PidUserMapper pidUserMapper;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | private String getCookie() {
|
| | | String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17784739772");
|
| | | JSONObject resultJSON = JSONObject.fromObject(result);
|
| | | if (resultJSON.optInt("code") == 0) {
|
| | | return resultJSON.optString("cookie");
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | private String getCookieBuXin() {
|
| | | String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17347953252");
|
| | | JSONObject resultJSON = JSONObject.fromObject(result);
|
| | | if (resultJSON.optInt("code") == 0) {
|
| | | return resultJSON.optString("cookie");
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | private void reportCookieInvalid() {
|
| | | String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17784739772");
|
| | | }
|
| | |
|
| | | private boolean createPid() {
|
| | |
|
| | | try {
|
| | | Thread.sleep(1000 * 3 + (int) (Math.random() * 5000));
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | Long count = tbPidMapper.count();
|
| | | |
| | | String name = "quanqudao_" + count;
|
| | |
|
| | | String cookies = getCookie();
|
| | | if (cookies == null) {
|
| | | try {
|
| | | Thread.sleep(1000 * 10);
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | createPid();
|
| | | }
|
| | |
|
| | | String url = "https://pub.alimama.com/common/adzone/selfAdzoneCreate.json";
|
| | | Map<String, String> headrers = new HashMap<>();
|
| | | headrers.put("Cookie", cookies);
|
| | | headrers.put("Origin", "http://pub.alimama.com");
|
| | | headrers.put("Referer", "ttp://pub.alimama.com/promo/search/index.htm");
|
| | | headrers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | | String[] sts = cookies.split(";");
|
| | | String token = "";
|
| | | for (String st : sts) {
|
| | | if (st.contains("_tb_token_")) {
|
| | | token = st.split("=")[1].trim();
|
| | | }
|
| | | }
|
| | |
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
|
| | | Map<String, String> params = new HashMap<>();
|
| | | params.put("tag", "29");
|
| | | params.put("gcid", "7");
|
| | | params.put("siteid", "56750082");
|
| | | params.put("selectact", "add");
|
| | |
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", token);
|
| | |
|
| | | params.put("newadzonename", name);
|
| | | String result = (post(url, params, headrers));
|
| | | JSONObject data = JSONObject.fromObject(result);
|
| | | if (data.optBoolean("ok")) {
|
| | | if (com.yeshi.fanli.util.StringUtil.isNullOrEmpty(data.optJSONObject("data").optString("adzoneId")))
|
| | | return false;
|
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
|
| | | data.optJSONObject("data").optString("siteId"), data.optJSONObject("data").optString("adzoneId"));
|
| | | TBPid tbPid = new TBPid();
|
| | | tbPid.setCreatetime(System.currentTimeMillis());
|
| | | tbPid.setName(name);
|
| | | tbPid.setPid(pid);
|
| | | tbPidMapper.insertSelective(tbPid);
|
| | | return true;
|
| | | } else {
|
| | | System.out.println(result);
|
| | | }
|
| | |
|
| | | return false;
|
| | | }
|
| | |
|
| | | private boolean createPidBuXin() {
|
| | |
|
| | | try {
|
| | | Thread.sleep(1000 * 3 + (int) (Math.random() * 5000));
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | Long count = tbPidMapper.count();
|
| | | |
| | | String name = "tuiguang_" + count;
|
| | |
|
| | | String cookies = getCookieBuXin();
|
| | | if (cookies == null) {
|
| | | try {
|
| | | Thread.sleep(1000 * 10);
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | createPidBuXin();
|
| | | }
|
| | |
|
| | | String url = "http://pub.alimama.com/common/adzone/selfAdzoneCreate.json";
|
| | | Map<String, String> headrers = new HashMap<>();
|
| | | headrers.put("Cookie", cookies);
|
| | | headrers.put("Origin", "http://pub.alimama.com");
|
| | | headrers.put("Referer", "ttp://pub.alimama.com/promo/search/index.htm");
|
| | | headrers.put("User-Agent",
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
|
| | | String[] sts = cookies.split(";");
|
| | | String token = "";
|
| | | for (String st : sts) {
|
| | | if (st.contains("_tb_token_")) {
|
| | | token = st.split("=")[1].trim();
|
| | | }
|
| | | }
|
| | |
|
| | | Map<String, String> params = new HashMap<>();
|
| | |
|
| | | double random = Math.random();
|
| | | if (random > 0.6) {// android
|
| | | params.put("tag", "29");
|
| | | params.put("gcid", "7");
|
| | | params.put("siteid", "45750814");
|
| | | } else if (random > 0.3) // IOS
|
| | | {
|
| | | params.put("tag", "29");
|
| | | params.put("gcid", "7");
|
| | | params.put("siteid", "45820106");
|
| | | } else// 导购
|
| | | {
|
| | | params.put("tag", "29");
|
| | | params.put("gcid", "8");
|
| | | params.put("siteid", "45882200");
|
| | | }
|
| | | params.put("selectact", "add");
|
| | |
|
| | | params.put("t", System.currentTimeMillis() + "");
|
| | | params.put("_tb_token_", token);
|
| | |
|
| | | params.put("newadzonename", name);
|
| | | String result = (post(url, params, headrers));
|
| | | JSONObject data = JSONObject.fromObject(result);
|
| | | if (data.optBoolean("ok")) {
|
| | | if (com.yeshi.fanli.util.StringUtil.isNullOrEmpty(data.optJSONObject("data").optString("adzoneId")))
|
| | | return false;
|
| | | String pid = String.format("mm_133239778_%s_%s", data.optJSONObject("data").optString("siteId"),
|
| | | data.optJSONObject("data").optString("adzoneId"));
|
| | | TBPid tbPid = new TBPid();
|
| | | tbPid.setCreatetime(System.currentTimeMillis());
|
| | | tbPid.setName(name);
|
| | | tbPid.setPid(pid);
|
| | | tbPidMapper.insert(tbPid);
|
| | | return true;
|
| | | } else {
|
| | | System.out.println(result);
|
| | | }
|
| | |
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void startCreatePid() {
|
| | | for (int i = 1; i < 50000; i++) {
|
| | | try {
|
| | | createPid();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | try {
|
| | | // 沉睡1分钟再试
|
| | | Thread.sleep(1000 * 60L);
|
| | | } catch (InterruptedException e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | private String post(String url, Map<String, String> map, Map<String, String> headers) {
|
| | | Iterator<String> its = map.keySet().iterator();
|
| | | NameValuePair[] params = new NameValuePair[map.keySet().size()];
|
| | | int p = 0;
|
| | | while (its.hasNext()) {
|
| | | String key = its.next();
|
| | | NameValuePair np = new NameValuePair(key, map.get(key));
|
| | | params[p] = np;
|
| | | p++;
|
| | | }
|
| | |
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod method = new PostMethod(url);
|
| | |
|
| | | if (headers != null) {
|
| | | its = headers.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | String key = its.next();
|
| | | method.addRequestHeader(key, headers.get(key));
|
| | | }
|
| | | }
|
| | |
|
| | | method.setRequestBody(params);
|
| | | try {
|
| | | client.executeMethod(method);
|
| | | return method.getResponseBodyAsString();
|
| | | } catch (HttpException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "";
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public TBPid getTBPid(Long uid, int type) {
|
| | | // 已经分配同类型的PID
|
| | | PidUser pidUser = pidUserMapper.selectLatestByUidAndType(uid, type);
|
| | |
|
| | | if (type == PidUser.TYPE_SHARE_GOODS && pidUser != null) {// 分享赚特殊处理
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(type);
|
| | | String pid = pidUser.getPid();
|
| | | String appId = pid.split("_")[2];
|
| | | if (configList.get(0).getAppId().equalsIgnoreCase(appId)) {
|
| | | TBPid tbPid = new TBPid();
|
| | | tbPid.setPid(pidUser.getPid());
|
| | | return tbPid;
|
| | | }
|
| | | } else {
|
| | | if (pidUser != null) {
|
| | | TBPid tbPid = new TBPid();
|
| | | tbPid.setPid(pidUser.getPid());
|
| | | return tbPid;
|
| | | }
|
| | | }
|
| | | TBPid tbPid = null;
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(type);
|
| | | // 以查询到的第一个为主PID,当主PID缺失的时候采用其他PID
|
| | | for (TaoBaoUnionConfig config : configList) {
|
| | | String prefix = String.format("mm_%s_%s_", config.getAccountId(), config.getAppId());
|
| | | tbPid = tbPidMapper.selectAvailablePid(prefix.replace("_", "\\_") + "%");
|
| | | if (tbPid != null) {
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | if (tbPid != null) {
|
| | | // 将先前的PID设置为已用
|
| | | TBPid updateTBPid = new TBPid();
|
| | | updateTBPid.setId(tbPid.getId());
|
| | | updateTBPid.setUsed(true);
|
| | | tbPidMapper.updateByPrimaryKeySelective(updateTBPid);
|
| | | // 插入对应的用户PID映射
|
| | | pidUser = new PidUser();
|
| | | pidUser.setPid(tbPid.getPid());
|
| | | pidUser.setUid(uid);
|
| | | pidUser.setType(type);
|
| | | pidUserMapper.insertSelective(pidUser);
|
| | | return tbPid;
|
| | | } else {
|
| | | LogHelper.error("无PID可用:" + type);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ClientTBPid getAndroidDefault() {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | | String pid = configList.get(0).getDefaultPid();
|
| | | String siteId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | return new ClientTBPid(configList.get(0).getAppKey(), pid, siteId, adzoneId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ClientTBPid getIOSDefault() {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_IOS);
|
| | | String pid = configList.get(0).getDefaultPid();
|
| | | String siteId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | return new ClientTBPid(configList.get(0).getAppKey(), pid, siteId, adzoneId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void startCreatePidBuXinJie() {
|
| | | for (int i = 1; i < 50000; i++) {
|
| | | try {
|
| | | createPidBuXin();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | try {
|
| | | // 沉睡1分钟再试
|
| | | Thread.sleep(1000 * 60L);
|
| | | } catch (InterruptedException e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | | import org.apache.commons.httpclient.HttpException; |
| | | import org.apache.commons.httpclient.NameValuePair; |
| | | import org.apache.commons.httpclient.methods.PostMethod; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.HttpUtil; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.share.PidUserMapper; |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TBPidMapper; |
| | | import com.yeshi.fanli.entity.taobao.ClientTBPid; |
| | | import com.yeshi.fanli.entity.taobao.PidUser; |
| | | import com.yeshi.fanli.entity.taobao.TBPid; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; |
| | | import com.yeshi.fanli.service.inter.user.TBPidService; |
| | | import com.yeshi.fanli.util.TaoBaoConstant; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Service |
| | | public class TBPidServiceImpl implements TBPidService { |
| | | |
| | | @Resource |
| | | private TBPidMapper tbPidMapper; |
| | | |
| | | @Resource |
| | | private PidUserMapper pidUserMapper; |
| | | |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | private String getCookie() { |
| | | String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17784739772"); |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | | if (resultJSON.optInt("code") == 0) { |
| | | return resultJSON.optString("cookie"); |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private String getCookieBuXin() { |
| | | String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17347953252"); |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | | if (resultJSON.optInt("code") == 0) { |
| | | return resultJSON.optString("cookie"); |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private void reportCookieInvalid() { |
| | | String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17784739772"); |
| | | } |
| | | |
| | | private boolean createPid() { |
| | | |
| | | try { |
| | | Thread.sleep(1000 * 3 + (int) (Math.random() * 5000)); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | Long count = tbPidMapper.count(); |
| | | |
| | | String name = "quanqudao_" + count; |
| | | |
| | | String cookies = getCookie(); |
| | | if (cookies == null) { |
| | | try { |
| | | Thread.sleep(1000 * 10); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | createPid(); |
| | | } |
| | | |
| | | String url = "https://pub.alimama.com/common/adzone/selfAdzoneCreate.json"; |
| | | Map<String, String> headrers = new HashMap<>(); |
| | | headrers.put("Cookie", cookies); |
| | | headrers.put("Origin", "http://pub.alimama.com"); |
| | | headrers.put("Referer", "ttp://pub.alimama.com/promo/search/index.htm"); |
| | | headrers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | String[] sts = cookies.split(";"); |
| | | String token = ""; |
| | | for (String st : sts) { |
| | | if (st.contains("_tb_token_")) { |
| | | token = st.split("=")[1].trim(); |
| | | } |
| | | } |
| | | |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("tag", "29"); |
| | | params.put("gcid", "7"); |
| | | params.put("siteid", "56750082"); |
| | | params.put("selectact", "add"); |
| | | |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", token); |
| | | |
| | | params.put("newadzonename", name); |
| | | String result = (post(url, params, headrers)); |
| | | JSONObject data = JSONObject.fromObject(result); |
| | | if (data.optBoolean("ok")) { |
| | | if (com.yeshi.fanli.util.StringUtil.isNullOrEmpty(data.optJSONObject("data").optString("adzoneId"))) |
| | | return false; |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | data.optJSONObject("data").optString("siteId"), data.optJSONObject("data").optString("adzoneId")); |
| | | TBPid tbPid = new TBPid(); |
| | | tbPid.setCreatetime(System.currentTimeMillis()); |
| | | tbPid.setName(name); |
| | | tbPid.setPid(pid); |
| | | tbPidMapper.insertSelective(tbPid); |
| | | return true; |
| | | } else { |
| | | System.out.println(result); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | private boolean createPidBuXin() { |
| | | |
| | | try { |
| | | Thread.sleep(1000 * 3 + (int) (Math.random() * 5000)); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | Long count = tbPidMapper.count(); |
| | | |
| | | String name = "tuiguang_" + count; |
| | | |
| | | String cookies = getCookieBuXin(); |
| | | if (cookies == null) { |
| | | try { |
| | | Thread.sleep(1000 * 10); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | createPidBuXin(); |
| | | } |
| | | |
| | | String url = "http://pub.alimama.com/common/adzone/selfAdzoneCreate.json"; |
| | | Map<String, String> headrers = new HashMap<>(); |
| | | headrers.put("Cookie", cookies); |
| | | headrers.put("Origin", "http://pub.alimama.com"); |
| | | headrers.put("Referer", "ttp://pub.alimama.com/promo/search/index.htm"); |
| | | headrers.put("User-Agent", |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); |
| | | String[] sts = cookies.split(";"); |
| | | String token = ""; |
| | | for (String st : sts) { |
| | | if (st.contains("_tb_token_")) { |
| | | token = st.split("=")[1].trim(); |
| | | } |
| | | } |
| | | |
| | | Map<String, String> params = new HashMap<>(); |
| | | |
| | | double random = Math.random(); |
| | | if (random > 0.6) {// android |
| | | params.put("tag", "29"); |
| | | params.put("gcid", "7"); |
| | | params.put("siteid", "45750814"); |
| | | } else if (random > 0.3) // IOS |
| | | { |
| | | params.put("tag", "29"); |
| | | params.put("gcid", "7"); |
| | | params.put("siteid", "45820106"); |
| | | } else// 导购 |
| | | { |
| | | params.put("tag", "29"); |
| | | params.put("gcid", "8"); |
| | | params.put("siteid", "45882200"); |
| | | } |
| | | params.put("selectact", "add"); |
| | | |
| | | params.put("t", System.currentTimeMillis() + ""); |
| | | params.put("_tb_token_", token); |
| | | |
| | | params.put("newadzonename", name); |
| | | String result = (post(url, params, headrers)); |
| | | JSONObject data = JSONObject.fromObject(result); |
| | | if (data.optBoolean("ok")) { |
| | | if (com.yeshi.fanli.util.StringUtil.isNullOrEmpty(data.optJSONObject("data").optString("adzoneId"))) |
| | | return false; |
| | | String pid = String.format("mm_133239778_%s_%s", data.optJSONObject("data").optString("siteId"), |
| | | data.optJSONObject("data").optString("adzoneId")); |
| | | TBPid tbPid = new TBPid(); |
| | | tbPid.setCreatetime(System.currentTimeMillis()); |
| | | tbPid.setName(name); |
| | | tbPid.setPid(pid); |
| | | tbPidMapper.insert(tbPid); |
| | | return true; |
| | | } else { |
| | | System.out.println(result); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public void startCreatePid() { |
| | | for (int i = 1; i < 50000; i++) { |
| | | try { |
| | | createPid(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | try { |
| | | // 沉睡1分钟再试 |
| | | Thread.sleep(1000 * 60L); |
| | | } catch (InterruptedException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | private String post(String url, Map<String, String> map, Map<String, String> headers) { |
| | | Iterator<String> its = map.keySet().iterator(); |
| | | NameValuePair[] params = new NameValuePair[map.keySet().size()]; |
| | | int p = 0; |
| | | while (its.hasNext()) { |
| | | String key = its.next(); |
| | | NameValuePair np = new NameValuePair(key, map.get(key)); |
| | | params[p] = np; |
| | | p++; |
| | | } |
| | | |
| | | HttpClient client = new HttpClient(); |
| | | PostMethod method = new PostMethod(url); |
| | | |
| | | if (headers != null) { |
| | | its = headers.keySet().iterator(); |
| | | while (its.hasNext()) { |
| | | String key = its.next(); |
| | | method.addRequestHeader(key, headers.get(key)); |
| | | } |
| | | } |
| | | |
| | | method.setRequestBody(params); |
| | | try { |
| | | client.executeMethod(method); |
| | | return method.getResponseBodyAsString(); |
| | | } catch (HttpException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public TBPid getTBPid(Long uid, int type) { |
| | | // 已经分配同类型的PID |
| | | PidUser pidUser = pidUserMapper.selectLatestByUidAndType(uid, type); |
| | | |
| | | if (type == PidUser.TYPE_SHARE_GOODS && pidUser != null) {// 分享赚特殊处理 |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(type); |
| | | String pid = pidUser.getPid(); |
| | | String appId = pid.split("_")[2]; |
| | | if (configList.get(0).getAppId().equalsIgnoreCase(appId)) { |
| | | TBPid tbPid = new TBPid(); |
| | | tbPid.setPid(pidUser.getPid()); |
| | | return tbPid; |
| | | } |
| | | } else { |
| | | if (pidUser != null) { |
| | | TBPid tbPid = new TBPid(); |
| | | tbPid.setPid(pidUser.getPid()); |
| | | return tbPid; |
| | | } |
| | | } |
| | | TBPid tbPid = null; |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(type); |
| | | // 以查询到的第一个为主PID,当主PID缺失的时候采用其他PID |
| | | for (TaoBaoUnionConfig config : configList) { |
| | | String prefix = String.format("mm_%s_%s_", config.getAccountId(), config.getAppId()); |
| | | tbPid = tbPidMapper.selectAvailablePid(prefix.replace("_", "\\_") + "%"); |
| | | if (tbPid != null) { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (tbPid != null) { |
| | | // 将先前的PID设置为已用 |
| | | TBPid updateTBPid = new TBPid(); |
| | | updateTBPid.setId(tbPid.getId()); |
| | | updateTBPid.setUsed(true); |
| | | tbPidMapper.updateByPrimaryKeySelective(updateTBPid); |
| | | // 插入对应的用户PID映射 |
| | | pidUser = new PidUser(); |
| | | pidUser.setPid(tbPid.getPid()); |
| | | pidUser.setUid(uid); |
| | | pidUser.setType(type); |
| | | pidUserMapper.insertSelective(pidUser); |
| | | return tbPid; |
| | | } else { |
| | | LogHelper.error("无PID可用:" + type); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public ClientTBPid getAndroidDefault() { |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | String pid = configList.get(0).getDefaultPid(); |
| | | String siteId = pid.split("_")[2]; |
| | | String adzoneId = pid.split("_")[3]; |
| | | return new ClientTBPid(configList.get(0).getAppKey(), pid, siteId, adzoneId); |
| | | } |
| | | |
| | | @Override |
| | | public ClientTBPid getIOSDefault() { |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_IOS); |
| | | String pid = configList.get(0).getDefaultPid(); |
| | | String siteId = pid.split("_")[2]; |
| | | String adzoneId = pid.split("_")[3]; |
| | | return new ClientTBPid(configList.get(0).getAppKey(), pid, siteId, adzoneId); |
| | | } |
| | | |
| | | @Override |
| | | public void startCreatePidBuXinJie() { |
| | | for (int i = 1; i < 50000; i++) { |
| | | try { |
| | | createPidBuXin(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | try { |
| | | // 沉睡1分钟再试 |
| | | Thread.sleep(1000 * 60L); |
| | | } catch (InterruptedException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ClientTBPid getSharePid(SystemEnum system) { |
| | | String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share); |
| | | ClientTBPid clientTBPid = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY, pid, pid.split("_")[2], |
| | | pid.split("_")[3]); |
| | | return clientTBPid; |
| | | } |
| | | } |