主要實(shí)現(xiàn)功能:關(guān)注公眾號(hào)的用戶發(fā)送拼多多商品鏈接,后臺(tái)程序通過(guò)鏈接查找商品優(yōu)惠券或返傭情況。
說(shuō)明:使用了niltor?封裝的拼多多接口?github地址?,但是需要注意可能會(huì)存在返回模型無(wú)法正確解析,導(dǎo)致沒(méi)有正確返回?cái)?shù)據(jù)的問(wèn)題。使用的過(guò)程中修改下返回模型屬性類(lèi)型就好了。
最終實(shí)現(xiàn)效果如下:
代碼實(shí)現(xiàn):
public async System.Threading.Tasks.Task<string> GetPddCouponAsync(ExmlMsg xmlMsg)
{
//通過(guò)正則表達(dá)式解析拼多多商品鏈接,獲取拼多多商品Id
string msg = xmlMsg.Content;
Match m_goods = Regex.Match(msg, @"(?<=goods_id=)([0-9]*)");
string goods_id = m_goods.Value;
if (string.IsNullOrEmpty(goods_id))
{
LogHelper.WriteLog(typeof(WechatController), "獲取拼多多goods id失敗" + msg);
return "";
}
//調(diào)用之前需要先注冊(cè)PddOpenSdk服務(wù)
/*
PddCommonApi.ClientId = "d8172a66ddf14220beac58e8eddca0d9";
PddCommonApi.ClientSecret = "d5993ce16cc0d1bd35403176f35544962e786645";
PddCommonApi.RedirectUri = "RedirectUri";
*/
DdkApi api = new DdkApi();
var model = new DetailDdkGoodsRequestModel()
{
Type = "pdd.ddk.goods.detail",
GoodsIdList = $"[{goods_id}]"
};
DetailDdkGoodsResponseModel result = null;
try
{
result = await api.DetailDdkGoodsAsync(model);
}
catch(Exception ex)
{
LogHelper.WriteLog(typeof(WechatController), "調(diào)用拼多多獲取商品詳細(xì)信息失敗" + ex.Message);
return "";
}
var goods = result.GoodsDetailResponse.GoodsDetails.FirstOrDefault();
if (goods==null) //無(wú)優(yōu)惠券 無(wú)傭金
{
return "/:rose 親,這款商品的優(yōu)惠返利活動(dòng)結(jié)束了~
請(qǐng)換個(gè)商品試試吧。
========================
ue231 <a href='https://mobile.yangkeduo.com/duo_cms_mall.html?pid=2495191_31302208cpsSign=CM2495191_31302208_3a1c1a0431608b9c1eb417183d57c1bdduoduo_type=2'>拼多多優(yōu)惠券商城</a>
下單確認(rèn)收貨后就能收到返利傭金啦~";
}
else if(goods.HasCoupon) //有優(yōu)惠券 有傭金
{
try
{
var promotionUrlModel = await api.GenerateDdkGoodsPromotionUrlAsync(new GenerateDdkGoodsPromotionUrlRequestModel
{
Type = "pdd.ddk.goods.promotion.url.generate",
PId = pdd_pid,
GoodsIdList = $"[{goods_id}]",
GenerateShortUrl = true,
CustomParameters = xmlMsg.FromUserName
});
return $"/:rose 親,商品信息如下~
========================
{goods.GoodsName}
【在售價(jià)】{((decimal)goods.MinGroupPrice) / 100}元
【券后價(jià)】{Math.Round(((decimal)(goods.MinGroupPrice - goods.CouponDiscount.Value)) / 100, 2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>點(diǎn)擊這里下單</a>
下單確認(rèn)收貨后就能收到返利傭金啦~";
}
catch (Exception ex)
{
LogHelper.WriteLog(typeof(WechatController), "調(diào)用拼多多獲取推廣鏈接失敗" + ex.Message);
return "";
}
}
else //無(wú)優(yōu)惠券 但有傭金
{
try
{
var promotionUrlModel = await api.GenerateDdkGoodsPromotionUrlAsync(new GenerateDdkGoodsPromotionUrlRequestModel
{
Type = "pdd.ddk.goods.promotion.url.generate",
GoodsIdList = $"[{goods_id}]",
PId = pdd_pid,
GenerateShortUrl = true,
CustomParameters = xmlMsg.FromUserName
});
return $"/:rose 親,商品信息如下~
========================
{goods.GoodsName}
【在售價(jià)】{((decimal)goods.MinGroupPrice) / 100}元
【約返利】{Math.Round((decimal)(goods.MinGroupPrice * goods.PromotionRate) / 100000,2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>點(diǎn)擊這里下單</a>
下單確認(rèn)收貨后就能收到返利傭金啦~
點(diǎn)擊查看 <a href='http://mp.weixin.qq.com/s?__biz=Mzg2NTAxOTEyMA==&mid=100000146&idx=1&sn=62405c8df3db46e74940aefb9ac3737b&chksm=4e61340d7916bd1bf645afbc6d10c1f19561d7fa59847516c01e64c0791e6d544f4f56c4f498#rd'>如何領(lǐng)取返利</a>";
}catch(Exception ex)
{
LogHelper.WriteLog(typeof(WechatController), "調(diào)用拼多多獲取推廣鏈接失敗" + ex.Message);
return "";
}
}
}
軟件構(gòu)成:一個(gè)主進(jìn)程exe和一個(gè)注入的dll
主進(jìn)程exe:把dll注入到微信,發(fā)送指令給dll,接受dll的信息
注入的dll:被注入到微信內(nèi)部,攔截微信的數(shù)據(jù),調(diào)用微信的功能
接收主進(jìn)程的指令,執(zhí)行指令對(duì)應(yīng)的操作、發(fā)信息給主進(jìn)程
exe和dll通訊:
exe
接收消息
創(chuàng)建一個(gè)可見(jiàn)的主界面
設(shè)置接受消息的回調(diào)函數(shù)
發(fā)送信息
LRESULT SendMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam)
dll
接收消息
創(chuàng)建一個(gè)不可見(jiàn)的界面
設(shè)置接受消息的回調(diào)函數(shù)
發(fā)送信息
LRESULT SendMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam)
源碼:?https://github.com/KongKong20/WeChatPCHook
本文摘自 :https://blog.51cto.com/u