第一步、先根据大淘客的API接口获取每日推荐的产品。
CString strUrl;
CWeb html;
SENDINFO si;
CString strRet, strPostData;
strUrl.Format(_T("https://openapi.dataoke.com/api/goods/get-ranking-list?appKey=%s&version=%s&rankType=%s&sign=%s"), APP_KEY, _T("1.1.2"), m_strCurType, sign);
if (html.Get(strUrl, strPostData, strRet, si))
{
CStringA strAJson = _W2A(strRet);
Json::Reader reader;
Json::Value root;
if (!reader.parse(strAJson.GetBuffer(strAJson.GetLength()), root))
{
return;
}
strAJson.ReleaseBuffer();
if (root.isNull())
{
return;
}
CString strContent = root["msg"].asCString();
if (strContent.CompareNoCase(_T("成功")) != 0)
{
return;
}
for (UINT i = 0; i < root["data"].size(); i++)
{
if (!root["data"][i]["goodsList"].isNull())//如果是类型5,6 里面含有goodsList
{
ReadProductList(root["data"][i]["goodsList"]);
}
else
{
ReadProductList(root["data"]);
break;
}
}
}
其中的APP KEY这些需要到大淘客网站去申请开发者,即可获取。
将宝贝通过在内存中直接加载图片的方式,显示前100的宝贝。
我们可以将需要的宝贝直接填加到 列表中,等待发到微信群里。以便给群友们共享宝贝,领券后再购买确实便宜不少呢!
2、本文程序使用c++ + duilib。直接在喜欢的宝贝上点选,然后点 “加入发送列表” 即可进入发送队列里:
发送宝贝时进行一些转换、过滤等。比如二合一的转链,可以生成一个短链接和淘口令等。
参数设置界面:
发送代码的实现片段:
int rnd = 0;
while (m_bThreadWorking)
{
for (int i = 0; m_bThreadWorking && i < m_pListData->GetCount(); i++)
{
CListTextExtElementUI* pItem = (CListTextExtElementUI*)m_pListData->GetItemAt(i);
CString strStatus = pItem->GetText(7);
if (strStatus.CompareNoCase(SEND_STATUS) == 0 )
{
continue;
}
ProductInfo* pi = (ProductInfo*)pItem->GetTag();
//条件:佣金低于设置的不发
if (option_commission && pi->commissionRate<commission_min)
{
continue;
}
//生成二合一链接
CString strLink = GetTransLink(pi->goodsId,pi->couponId, strPid);
strLink.Trim();
if( strLink.IsEmpty() )
continue;
//先发送一张图片 先下载再发送
CString strPicName = pi->strPicMain.Right(pi->strPicMain.GetLength() - pi->strPicMain.ReverseFind('/') - 1);
CString strPicPath;
strPicPath.Format(_T("%s\\%s"), m_strLocPicTempPath, strPicName);
if (!CWeb::SaveImg(pi->strPicMain, strPicPath))
{
continue;
}
//获取勾选要的微信群
for (int i=0;i< m_pList_group_target->GetCount();i++)
{
CListContainerElementUI* pListItem = (CListContainerElementUI*)m_pList_group_target->GetItemAt(i);
CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(pListItem->FindSubControl(_T("check")));
if (!pCheck->GetCheck())
{
continue;
}
UserInfo* pUsers = (UserInfo*)pListItem->GetTag();
Message msg;
wcscpy_s( msg.wxid , pUsers->UserId);
CString strinfo;
strinfo.Format(_T("<本地图片 路径=\"%s\">"), strPicPath);
TagMsgSend(m_parent, strinfo, &msg);
rnd = GetRandomNum(intenal_random_min, intenal_random_max);
rnd *= 1000;
MySleep(intenal_pic_words + rnd, m_bThreadWorking);//同一个群消息间隔
再发送一图文链接
//strinfo.Format(_T("<图文 标题=\"%s\" 描述=\"%s\" 图片=\"%s\" 链接=\"%s\">"),
// pi->dtitle,pi->title,strPicPath, strLink);
//TagMsgSend(m_parent, strinfo, &msg);
//图文中包含淘宝的链接会屏蔽,使用淘口令 。<文字 内容="填写文字内容1">
strLink.Trim(_T("¥"));
CString strMobanTemp = strMoban;
strMobanTemp.Replace(_T("{标题}"), pi->dtitle);
CString strTemp;
strTemp.Format(_T("%.2lf"), pi->originalPrice);
strMobanTemp.Replace(_T("{原价}"), strTemp);
strTemp.Format(_T("%.2lf"), pi->actualPrice);
strMobanTemp.Replace(_T("{券后价}"), strTemp);
strMobanTemp.Replace(_T("{淘口令}"), strLink);
strinfo.Format(_T("<文字 内容=\"%s\">"), strMobanTemp);
rnd = GetRandomNum(intenal_random_min, intenal_random_max);
rnd *= 1000;
TagMsgSend(m_parent, strinfo, &msg);
MySleep(intenal_qun + rnd, m_bThreadWorking);//群间隔
}
pItem->SetText(7, SEND_STATUS);
break;
}
rnd = GetRandomNum(intenal_random_min, intenal_random_max);
rnd *= 1000;
MySleep(intenal_product + rnd, m_bThreadWorking);//产品消息间隔
}
3、发送到微信必须要获取PC端微信的发送消息CALL,这个CALL地址是:0x2FA7F0。
void SendTextMessage(wchar_t* wxid, wchar_t* msg)
{
//拿到发送消息的call的地址
DWORD dwSendCallAddr = (DWORD)GetModuleHandle(TEXT("WeChatWin.dll")) + WxSendMessage;
//组装微信ID/群ID的结构体
wxMsg id = { 0 };
id.pMsg = wxid;
id.msgLen = wcslen(wxid);
id.buffLen = wcslen(wxid) * 2;
//消息内容
wxMsg text = { 0 };
text.pMsg = msg;
text.msgLen = wcslen(msg);
text.buffLen = wcslen(msg) * 2;
//取出微信ID和消息的地址
char* pWxid = (char*)&id.pMsg;
char* pWxmsg = (char*)&text.pMsg;
char buff[0x81C] = { 0 };
//调用微信发送消息call
__asm {
mov edx, pWxid;
push 0x1;
push 0;
mov ebx, pWxmsg;
push ebx;
lea ecx, buff;
call dwSendCallAddr;
add esp, 0xC;
}
}
大致步骤就是这么几步,也蛮简单的!